Question

I am programming in Visual Studio 12 in Asp.net using C#.

I have a chart that consists of two Series. All the points in the both the series are added like this

for (int i = 0; i < 1; i++)
{
  Chart2.Series[0].Points.AddXY("Jan", jR);
  Chart2.Series[0].Points.AddXY("Feb", fR);
}

jR and fR are integer values that are getting assigned as Y values for each X as Jan and Feb.

This same method applies to the second series.

How do I add legends programmatically after adding points to the series?

Any help would be much appreciated.

Was it helpful?

Solution

For more details see Legends

for (int i = 0; i < 1; i++)
{
    chart1.Series[0].Points.AddXY("Jan", i + 10);
    chart1.Series[0].Points.AddXY("Feb", i + 15);
}
// Create a new legend called "Legend1".
chart1.Legends.Add(new Legend("Legend1"));

// Set title
chart1.Legends["Legend1"].Title = "My legend";
// Assign the legend to Series1.
chart1.Series["Series1"].Legend = "Legend1";
chart1.Series["Series1"].IsVisibleInLegend = true;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top