Ich versuche, System.Windows.Controls.DataVisualization.Charting
Diagramm mit einigen ObservableCollection
zu koppeln.DataVisualization.Charting Diagramm funktioniert nicht mit ObservableList
Ich habe Klasse für einen Datenpunkt:
public class ChartDataPoint : INotifyPropertyChanged
{
private double xvalue;
public double XValue
{
get { return xvalue; }
set {
if (xvalue != value)
{
xvalue = value;
NotifyPropertyChanged("XValue");
}
}
}
private double yvalue;
public double YValue
{
get { return yvalue; }
set {
if (yvalue != value)
{
yvalue = value;
NotifyPropertyChanged("YValue");
}
}
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
private ChartDataPoint(double x, double y)
{
this.XValue = x;
this.YValue = y;
}
public static ChartDataPoint CreateNew(double x, double y)
{
return new ChartDataPoint(x, y);
}
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
Dann habe ich ObservableCollection<ChartDataPoint>
.
public MainWindow()
{
InitializeComponent();
ListSeries1Data.CollectionChanged += ListSeries1Data_CollectionChanged;
Chart1.DataContext = ListSeries1Data;
}
Nach meinem Fenster auftaucht ich auf einen Knopf klicken, die Artikel auf meine Liste ergänzt:
private void Button_Click(object sender, RoutedEventArgs e)
{
ListSeries1Data.Add(ChartDataPoint.CreateNew(i, r.Next(100)));
i++;
}
Und das ist mit diesem Diagramm Teil meiner XAML.
<c:Chart Name="Chart1" Background="WhiteSmoke">
<c:LineSeries Name="Series1"
Title="Read value"
IndependentValueBinding="{Binding Path=XValue}"
DependentValueBinding="{Binding Path=YValue}">
</c:LineSeries>
</c:Chart>
Was ist falsch an meinem Code?