Так я хочу, чтобы иметь возможность создавать диаграммы динамически для этого я создал следующий класс с методом, который называется getChart()
C# LineChart динамически DataBind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls.DataVisualization.Charting;
namespace Henvendelser
{
class ChartDataCreator
{
private Dictionary<String, List<ContactQueue>> dataList;
public ChartDataCreator() {
}
public Chart getChart(String choice) {
Chart c = new Chart();
LineSeries ls = new LineSeries();
ls.IndependentValueBinding="{Binding Path=Key}";
ls.DependentValueBinding="{Binding Path=Value}";
ls.ItemsSource =
new KeyValuePair<int, int>[]{
new KeyValuePair<int,int>(1, 12),
new KeyValuePair<int,int>(2, 25),
new KeyValuePair<int,int>(3, 5),
new KeyValuePair<int,int>(4, 6),
new KeyValuePair<int,int>(5, 10),
new KeyValuePair<int,int>(6, 4),
new KeyValuePair<int,int>(7, 40),
new KeyValuePair<int,int>(8, 12),
new KeyValuePair<int,int>(9, 25),
new KeyValuePair<int,int>(10, 5),
new KeyValuePair<int,int>(11, 6),
new KeyValuePair<int,int>(12, 10),
new KeyValuePair<int,int>(13, 4),
new KeyValuePair<int,int>(14, 8),
new KeyValuePair<int,int>(15, 9),
new KeyValuePair<int,int>(16, 50),
new KeyValuePair<int,int>(17, 40) };
c.Series.Add(ls);
return c;
}
}
}
Теперь, как вы можете видеть, что мой код имеет ошибку в:
ls.IndependentValueBinding="{Binding Path=Key}"; ls.DependentValueBinding="{Binding Path=Value}";
Мой вопрос: как вы динамически устанавливаете независимое и зависимое связывание. Также, пожалуйста, укажите, есть ли что-то еще, что не хватает, чтобы заставить его работать.
вместо bindInd.Source =; bindDep.Source = ; мог бы я сделать: ls.ItemsSource = List >(); ? –
вы можете разместить какой-либо связующий источник, который вы хотите там, я просто пытался показать это, вот где вы его выразите. – Bearcat9425