I have a C# app I'm building in Visual Studio 2010. The app contains code that crunches some input data to make some output data which I want to put on a chart. I can put the output data into any of the desired .NET collection objects. But I can't get the chart to look to an object defined on my form to get the chart's data. It seems the chart will only go to a service, database, or object that i开发者_如何学JAVAs external to my project.
I've reviewed all the posts I could find and it seems the chart object has evolved recently and the relevant posts aren't relevant any more because the Chart class has changed.
I've been working with the chart's DataSource property to specify the data source. I've also looked through all the options that come up with the automatic code completion facility of Visual Studio and can't find anything that looks or works like what I want.
This must be easy if one knows the trick. Anybody know the trick to this?
Thanks,
Bill
Eventually found the answer in MSDN under the heading "Adding Series Data at Run Time". Here is some example code I developed from the MSDN example code which shows the solution to my problem:
chart1.Series.Add("example");
chart1.Series["example"].ChartType = System.Windows.Forms.DataVisualization.
Charting.SeriesChartType.Line;
for (int i = 0; i < 20; ++i)
{
chart1.Series["example"].Points.Add(2 * i);
}
Cheers,
Bill
精彩评论