在我的XAML文件中,我创建了一个ChartPlotter,然后在c#中创建了我的LineGraphs,并将它们加密到了我的ChartPlotter上。我试图在这些LineGraphs创建后找到一种更新它们的方法,但始终失败。
我找到的唯一解决方案是删除所有LineGraphs,用新值重新创建它们,最后将它们链接到我的ChartPlotter。
如何更新LineGraph?
for (int i = 0; i < lgs.Length; i++)
if (lgs[i] != null)
lgs[i].RemoveFromPlotter();PS : lgs是我的LineGraph数组。
发布于 2014-05-21 15:54:14
要更新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);https://stackoverflow.com/questions/23786603
复制相似问题