Microsoft图表控件 - Xml绑定?! C#

时间:2022-11-17 15:55:36

I have an xml file:

我有一个xml文件:

<Database>
<Stat>
<Date>06/07/2009 00:00:00</Date> 
 <DayOfWeek>Monday</DayOfWeek> 
 <SentNumber>3248</SentNumber> 
 <ReceivedNumber>50</ReceivedNumber> 
 </Stat>
<Stat>
 <Date>07/07/2009 00:00:00</Date> 
 <DayOfWeek>Tuesday</DayOfWeek> 
 <SentNumber>1000</SentNumber> 
 <ReceivedNumber>500</ReceivedNumber> 
 </Stat>
 </Database>

I want to populate a Microsoft Chart Control bar chart in C# with the contents however i'm very confused about how to do this from the available tutorials. Any help would be greatly appreciated!

我想在C#中使用内容填充Microsoft Chart Control条形图但是我对如何从可用教程中执行此操作感到非常困惑。任何帮助将不胜感激!

1 个解决方案

#1


Could you provide a link to where you got the Chart Control you're using? I don't see a chart control in my VS 2008 toolbox.

你能提供一个链接到你正在使用的图表控件的位置吗?我在VS 2008工具箱中看不到图表控件。

So, I'm not familiar with the chart control you're using, but I have done lots of data binding to DataGridView controls.

所以,我不熟悉您正在使用的图表控件,但我已经完成了大量数据绑定到DataGridView控件。

If it works the same way, then you should be able to populate an XDocument (via the Load or Parse methods) with your XML data and then use LINQ to query the data you want to display in your chart. Once you have your query, then use the ToList extension method to generate a List that you can assign to the DataSource property of your chart.

如果它以相同的方式工作,那么您应该能够使用XML数据填充XDocument(通过Load或Parse方法),然后使用LINQ查询要在图表中显示的数据。获得查询后,使用ToList扩展方法生成可以分配给图表的DataSource属性的List。

#1


Could you provide a link to where you got the Chart Control you're using? I don't see a chart control in my VS 2008 toolbox.

你能提供一个链接到你正在使用的图表控件的位置吗?我在VS 2008工具箱中看不到图表控件。

So, I'm not familiar with the chart control you're using, but I have done lots of data binding to DataGridView controls.

所以,我不熟悉您正在使用的图表控件,但我已经完成了大量数据绑定到DataGridView控件。

If it works the same way, then you should be able to populate an XDocument (via the Load or Parse methods) with your XML data and then use LINQ to query the data you want to display in your chart. Once you have your query, then use the ToList extension method to generate a List that you can assign to the DataSource property of your chart.

如果它以相同的方式工作,那么您应该能够使用XML数据填充XDocument(通过Load或Parse方法),然后使用LINQ查询要在图表中显示的数据。获得查询后,使用ToList扩展方法生成可以分配给图表的DataSource属性的List。