使用 wpf 工具包动态创建图表
Dynamically create charts with wpf toolkit
我想在不使用 xmal 绑定依赖值和独立值的情况下动态创建一个 wpf 工具包的图表;此代码无效
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);
我想在不使用 xmal 绑定依赖值和独立值的情况下动态创建一个 wpf 工具包的图表;此代码无效
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);