我想动态创建一个图表wpf工具包,而无需使用xmal绑定依赖和独立值;该代码不起作用
Chart myChart = new Chart();
BarSeries colser = new BarSeries();
myChart.Width = 250;
myChart.Height = 250;
myChart.Title = "chart";
List<KeyValuePair<string, int>> valueList = new List<KeyValuePair<string, int>>();
valueList.Insert(0, new KeyValuePair<string, int>("TOR", 10));
valueList.Insert(1, new KeyValuePair<string, int>("SOC", 15));
valueList.Insert(2, new KeyValuePair<string, int>("BOS", 18));
valueList.Insert(3, new KeyValuePair<string, int>("NON", 11));
colser.Title = "title";
colser.IndependentValuePath = "Value";
colser.DependentValuePath = "Key";
colser.ItemsSource = valueList;
myChart.Series.Add(colser);
// added myChart to stackpanel as child
刚刚找到解决我问题的办法
var barSeries = new BarSeries
{
Title = "Fruit in Cupboard",
ItemsSource = new[]
{
new KeyValuePair<string, int>("TOR", 10),
new KeyValuePair<string, int>("SOC", 15),
new KeyValuePair<string, int>("BOS", 18),
new KeyValuePair<string, int>("NON", 11)
},
IndependentValueBinding = new Binding("Key"),
DependentValueBinding = new Binding("Value")
};
myChart.Series.Add(barSeries);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句