要更新LineGraphs,你必須使用ObservableDataSource對象,而不是CompositeDataSource的。有了這個對象,你可以使用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);
}
}
}
所有你想要的是在仿真的方法。
source1.AppendAsync(Dispatcher, p1);
謝謝,但我有這個錯誤 「調度員是一個類型,但使用像變量」 – JoE
的調度是從主窗口的attribut。如果你有這個錯誤,這意味着你沒有在主窗口類中編碼。如果是這樣,請將該調度員交給正在參與的班級:mainwindow.Dispatcher –
它的功能類似於魅力。謝謝 ! – JoE