开发者

How to get collection data into a chart object?

开发者 https://www.devze.com 2023-03-22 12:05 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消