S
S
Sasha Pleshakov2015-12-22 20:56:31
WPF
Sasha Pleshakov, 2015-12-22 20:56:31

How to add item to toolkit chart on button click?

<chartingToolkit:LineSeries Name="lineChart" 
        DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding Items}"/>

After adding a key pair, the value in the graph dictionary is not updated
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

2 answer(s)
M
Melz, 2015-12-23
@mnepoh

You need to update the binding or use another type instead of Dictionary.
ObservableCollection or anything with INotifyCollectionChanged / INotifyPropertyChanged .

S
Sasha Pleshakov, 2015-12-23
@mnepoh

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

But still nothing is added. It seems to me that I didn't screw up that much.
<chartingToolkit:LineSeries Name="lineChart" 
      DependentValuePath="Psuccess" IndependentValuePath="day" ItemsSource="{Binding Dots}"/>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question