Answer the question
In order to leave comments, you need to log in
How to add item to toolkit chart on button click?
<chartingToolkit:LineSeries Name="lineChart"
DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding Items}"/>
public Dictionary<int, double> Items = new Dictionary<int, double>(); // словарь с итемами графика
public void AddDotClick(object sender, RoutedEventArgs e)
{
int day = Convert.ToInt32(timeTextBox.Text);
double time = day * 86400; // перевод сутки в секунды
double Psuccess = Success(time);
Items.Add(day, Psuccess);
}
Answer the question
In order to leave comments, you need to log in
You need to update the binding or use another type instead of Dictionary.
ObservableCollection or anything with INotifyCollectionChanged / INotifyPropertyChanged .
I created an ObservableCollection in which the elements are a struct
public struct ChartDot
{
public int day;
public double Psuccess;
public ChartDot(int d, double p)
{
day = d;
Psuccess = p;
}
}
<chartingToolkit:LineSeries Name="lineChart"
DependentValuePath="Psuccess" IndependentValuePath="day" ItemsSource="{Binding Dots}"/>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question