I am trying to show the latest series value in a Legend for a FastLine type MS chart on a WinForm. I can have up to 10 series in a chart. I am using following code to add 3 columns (Symbol, Series Name, Value) in the Legend:
// Add Color column
LegendCellColumn firstColumn = new LegendCellColumn();
firstColumn.ColumnType = LegendCellColumnType.SeriesSymbol;
firstColumn.HeaderBackColor = System.Drawing.Color.WhiteSmoke;
chart1.Legends[0].CellColumns.Add(firstColumn);
// Add Legend Text column
LegendCellColumn secondColumn = new LegendCellColumn();
secondColumn.ColumnType = LegendCellColumnType.Text;
secondColumn.Text = "#LEGENDTEXT";
secondColumn.HeaderBackColor = System.Drawing.Color.WhiteSmoke;
chart1.Legends[0].CellColumns.Add(secondColumn);
// Add Total cell column
// I will set text for this column at runtime.
LegendCellColumn total = new LegendCellColumn();
total.Name = "Value";
total.HeaderBackColor = System.Drawing.Color.WhiteSmoke;
chart1.Legends[0].CellColumns.Add(total);
My question is - How do I access the legend for a specific series to show the runtime values? While adding new points to the Series if I do something like -
// Add new point to this series here
......
......
_chart.Legends[0].CellColumns[2].Text = runtimeValue.ToString();
then, a same value gets shown for all the series. This value is the latest for one of the series. It looks like -
---- Series1 45.21
---- Series2 45.21
---- Series3 45.21
---- Series4 45.21
How do I access a legend for each series so that I can set the individual value to show something like -
---- Series1 45.21
---- Series2 100
---- Series3 1.123
---- Series4 250.145
Here on SO, I have seen that some posts have mentioned that they can access the legend items by series such as -
myChartName.Legends["mySeriesName"]
I get an invalid argument exception If I try to do that which meant I can't access the legend by a series name. Am I missing something here?
Thanks for any help offered.