OxyPlot WPF如何提高渲染速度

时间:2018-02-24 03:42:46

标签: c# wpf oxyplot

我正在使用oxyplot散点图来加载数千个数据点(每个plotModel大约60000个)。更新绘图视图模型需要2.5秒。但我需要额外的5秒钟来渲染视觉效果。如何提高渲染速度?

在View中,它是一个列表视图,其中DataTemplate是OxyPlot。每个图都绑定到PlotModel。

在ViewModel中,我们通过实体框架从数据库获取数据并更新每个绘图模型

查看代码:

<ListView Grid.Column="1" ItemsSource="{Binding ArchiveRoutePlotModels , UpdateSourceTrigger=PropertyChanged, Mode=OneWay}">
    <ListView.ItemTemplate>
         <DataTemplate>
              <oxyPlot:PlotView Height="300" Width="1000" Model="{Binding RouteModel}">
              </oxyPlot:PlotView>
         </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

ViewModel代码:

    private void LoadArchiveJobRoutesMethod(string uuid)
    {
        Stopwatch sw = new Stopwatch();
        sw.Start();
        if (ArchiveRoutePlotModels.Count() > 0)
        {
            ArchiveRoutePlotModels.Clear();
        }
        using (ArchiveEntities _archiveSource = new ArchiveEntities())
        {

            _archiveSource.Loggings.Where(i => i.UUID == uuid).ToList().GroupBy(p => p.RouteId, (p, v) => new
            {
                RouteId = p,
                MeasureList = v,
            }).ToList().ForEach(p =>
            {
                App.Current.Dispatcher.Invoke((Action)delegate
                {
                    this.ArchiveRoutePlotModels.Add(new RoutePlotModel()
                    {
                        RouteId = (int)p.RouteId,
                        Minimum = (int)p.MeasureList.First().Id,
                        Maximum = (int)p.MeasureList.Last().Id,
                        RouteModel = new PlotModel()
                        {
                        }
                    });
                    this.ArchiveRoutePlotModels.Last().RouteModel.Axes.Add(new LinearAxis()
                    {
                        Position = AxisPosition.Bottom,
                        Unit = "Interval",
                        Minimum = p.MeasureList.First().Id,
                        Maximum = p.MeasureList.Last().Id
                    });
                    this.ArchiveRoutePlotModels.Last().RouteModel.Axes.Add(new LinearAxis()
                    {
                        Position = AxisPosition.Left,
                        Unit = "mm",
                        Minimum = -25,
                        Maximum = 100,
                        IsZoomEnabled = false
                    });
                    this.ArchiveRoutePlotModels.Last().RouteModel.Series.Add(new ScatterSeries()
                    {
                        Title = "Route " + p.RouteId.ToString(),
                        DataFieldX = "Index",
                        DataFieldY = "Y",
                        Background = OxyColors.Transparent,
                        IsVisible = true,
                    });
                    (this.ArchiveRoutePlotModels.Last().RouteModel.Series[0] as ScatterSeries).Points.AddRange(p.MeasureList.Select(m => new ScatterPoint(m.Id, (double)m.Value / 1000000 < 80.0 ? (double)m.Value / 1000000 : 80)).ToList());
                });
            });
            sw.Stop();
        }
        SystemPrompt = "OxyPlot Archive Plot Model Loading: " + sw.ElapsedMilliseconds + "ms ; Memory Usage" + (Process.GetCurrentProcess().WorkingSet64 / (1024 *1024)) + "MB";
    }

0 个答案:

没有答案