C# OxyPlot WPF如何提高渲染速度

C# OxyPlot WPF如何提高渲染速度,c#,wpf,oxyplot,C#,Wpf,Oxyplot,我使用oxyplot scatterline加载数千个数据点(每个plotModel大约60000个)。更新打印视图模型需要2.5秒。但是我需要额外的5秒钟来渲染视觉效果。如何提高渲染速度 在视图中,它是一个列表视图,其中DataTemplate是OxyPlot。每个打印都绑定到一个PlotModel 在ViewModel中,我们从数据库vie实体框架中获取数据,并更新每个绘图模型 查看代码: <ListView Grid.Column="1" ItemsSource="{Binding

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

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

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

查看代码:

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

视图模型代码:

    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";
    }
private void loadArchiveJobRouteMethod(字符串uuid)
{
秒表sw=新秒表();
sw.Start();
如果(ArchiveRoutePlotModels.Count()>0)
{
ArchiveRoutePlotModels.Clear();
}
使用(ArchiveEntities\u archiveSource=new ArchiveEntities())
{
_archiveSource.Loggings.Where(i=>i.UUID==UUID.ToList().GroupBy(p=>p.RouteId,(p,v)=>new
{
RouteId=p,
测量列表=v,
}).ToList().ForEach(p=>
{
App.Current.Dispatcher.Invoke((操作)委托
{
添加(新的RoutePlotModel()
{
RouteId=(int)p.RouteId,
最小值=(int)p.MeasureList.First().Id,
最大值=(int)p.MeasureList.Last().Id,
RouteModel=new PlotModel()
{
}
});
this.ArchiveRoutePlotModels.Last().RouteModel.Axes.Add(new LinearAxis())
{
位置=轴位置。底部,
Unit=“间隔”,
最小值=p.MeasureList.First().Id,
最大值=p.MeasureList.Last().Id
});
this.ArchiveRoutePlotModels.Last().RouteModel.Axes.Add(new LinearAxis())
{
位置=轴位置。左,
单位=“毫米”,
最小值=-25,
最大值=100,
IsZoomEnabled=false
});
this.ArchiveRoutePlotModels.Last().RouteModel.Series.Add(new ScatterSeries())
{
Title=“Route”+p.RouteId.ToString(),
DataFieldX=“索引”,
DataFieldY=“Y”,
背景=氧色。透明,
IsVisible=true,
});
(this.ArchiveRoutePlotModels.Last().RouteModel.Series[0]作为ScatterSeries).Points.AddRange(p.MeasureList.Select(m=>newscatterpoint(m.Id,(double)m.Value/1000000<80.0?(double)m.Value/1000000:80)).ToList();
});
});
sw.Stop();
}
SystemPrompt=“OxyPlot存档打印模型加载:”+sw.ElapsedMilliseconds+“ms;内存使用量”+(Process.GetCurrentProcess().WorkingSet64/(1024*1024))+“MB”;
}

UpdateSourceTrigger可以在xaml中省略。ToList()可能会影响性能。如果对RoutePlotModel和ScatterSeries使用局部变量,代码的可读性会更高。关于绘图速度,请考虑使用oxyplot的抽取功能。对于更新缓慢的原因,我会尝试分而治之:在更新的不同部分计时,缓慢可能与oxyplot无关,而是与您在将日期交给oxyplot之前对日期的处理有关。我严重怀疑是否有任何理由在图表中添加这么多点。考虑为了数据可视化的目的而对其进行过滤。如果您不需要“实时”显示它,那么您也可以按需动态绑定,这意味着,首先将数据添加到集合中,然后将其绑定到视图。
OxyPlot
此处所示仅在152毫秒内渲染193000多个点。所以,你的5000毫秒数字需要一个现实的检查@jsanalytics能否请您展示代码示例?@SolderingIronMen抱歉,我不再有此示例。。。