0
votes

I want to dynamically create a chart woth wpf toolkit without using xmal for binding dependant and independant values; this code is not working

            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
1

1 Answers

0
votes

Just found the slution to my problem

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);