2

In my XAML file, I create a ChartPlotter then I create in c# my LineGraphs and attatch them to my ChartPlotter. I tried to find a way to update these LineGraphs after their creation, but it always failed.

The only solution I found, is that I delete all LineGraphs , re-create them with new values and finally link them to my ChartPlotter.

How can I update LineGraph ?

for (int i = 0; i < lgs.Length; i++)
            if (lgs[i] != null)
                lgs[i].RemoveFromPlotter();

PS : lgs is my LineGraph array.

JoE
  • 43
  • 2
  • 8

1 Answers1

3

To update your LineGraphs, you have to use the ObservableDataSource object instead of the CompositeDataSource. With this object, you can use the method AppendAsync().

public partial class MainWindow : Window
{
    public ObservableDataSource<Point> source1 = null;

    public MainWindow()
    {
        InitializeComponent();
        this.Loaded += MainWindow_Loaded;
    }

    private void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        // Create source         
        source1 = new ObservableDataSource<Point>();
        // Set identity mapping of point in collection to point on plot
        source1.SetXYMapping(p => p);

        // Add the graph. Colors are not specified and chosen random
        plotter.AddLineGraph(source1, 2, "Data row");

        // Force everyting to fit in view
        plotter.Viewport.FitToView();

        // Start computation process in second thread
        Thread simThread = new Thread(new ThreadStart(Simulation));
        simThread.IsBackground = true;
        simThread.Start();
    }

    private void Simulation()
    {
        int i = 0;
        while (true)
        {
            Point p1 = new Point(i * i, i);
            source1.AppendAsync(Dispatcher, p1);

            i++;
            Thread.Sleep(1000);

        }
    }
}

All you want is in the while of the method Simulation.

source1.AppendAsync(Dispatcher, p1);
Jean Col
  • 522
  • 5
  • 16
  • Thanks but i had this error "Dispatcher is a type but is used like a variable" – JoE May 22 '14 at 08:41
  • The Dispatcher is an attribut from your mainwindow. If you have this error, it means that you are not coding in the mainwindow class. If so, give acces to that dispatcher to the class you are working on : mainwindow.Dispatcher – Jean Col May 22 '14 at 11:12