Cdd data to column series in wpf C#
I want to create a ColumnSeries Bar Chart in WPF using C#. I shall extract the data from t开发者_如何学运维he database and want to bind it to the bar chart.
The data extracted will contain two values. First is parameter name (string) and the other is its value (double). Which type of collection shall I use? and how to do the binding?
i finally used a simple KeyValuePair array and assigned it to the ItemsSource property of the ColumnSeries of barchart.
Just use the Dictionary as follows:
Dictionary<string,int> data = new Dictionary<string,int> ();
If you have a data in dataset then use foreach
loop for item in the dataset
Example:
foreach (DataRow drv in DS.Tables[0].Rows)
{
string strvalue= Convert.ToString(drv["columnname string type"]);
string intvalue= Convert.ToString(drv["column name int type"]);
data.Add(Convert.ToString(strvalue), Convert.ToInt32(intvalue));
}
((ColumnSeries)msChart3.Series[0]).ItemsSource = data;
This way you can bind data to a column series chart type.
精彩评论