如何提高 WinForms MSChart 性能?

发布于 2024-08-26 06:45:09 字数 1668 浏览 8 评论 0原文

我使用 MSChart 创建了一些简单的图表(FastLine 类型),并使用实时数据更新它们,如下所示:

MSCharts Level Chart

为此,我将自定义类型的可观察集合绑定到图表,如下所示:

                // set chart data source
            this._Chart.DataSource = value; //is of type ObservableCollection<SpectrumLevels>

            //define x and y value members for each series
            this._Chart.Series[0].XValueMember = "Index";
            this._Chart.Series[1].XValueMember = "Index";
            this._Chart.Series[0].YValueMembers = "Channel0Level";
            this._Chart.Series[1].YValueMembers = "Channel1Level";

            // bind data to chart
            this._Chart.DataBind(); //lasts 1.5 seconds for 8000 points per series

每次刷新时,数据集都会完全更改,这不是滚动更新!

通过分析器,我发现 DataBind() 调用大约需要 1.5 秒。其他调用可以忽略不计。

如何才能使其更快?

  • 我应该使用 ObservableCollection 之外的其他类型吗?可能是一个数组?
  • 我应该使用另一种形式的数据绑定吗?
  • MSChart 是否有一些我可能错过的调整?
  • 我应该使用一组稀疏的日期,每个像素只有一个值吗?
  • 我是否已达到 MSCharts 的性能极限?

从应用程序的类型来看,为了保持“流畅”,我们应该每秒进行多次刷新。

感谢您的任何提示!

编辑:leppie提出的解决方案:

                this._Chart.Series[0].Points.Clear();
            foreach (var item in value) //iterates over the list of custom objects
            {
                    this._Chart.Series[0].Points.Add(new DataPoint
                    {
                        XValue = item.Index,
                        YValues = new double[] { item.Channel0Level.Value }
                    });

            }

现在的速度提高了一倍多!

I have created some simple charts (of type FastLine) with MSChart and update them with live data, like below:

MSCharts Level Chart

To do so, I bind an observable collection of a custom type to the chart like so:

                // set chart data source
            this._Chart.DataSource = value; //is of type ObservableCollection<SpectrumLevels>

            //define x and y value members for each series
            this._Chart.Series[0].XValueMember = "Index";
            this._Chart.Series[1].XValueMember = "Index";
            this._Chart.Series[0].YValueMembers = "Channel0Level";
            this._Chart.Series[1].YValueMembers = "Channel1Level";

            // bind data to chart
            this._Chart.DataBind(); //lasts 1.5 seconds for 8000 points per series

At each refresh, the dataset completely changes, it is not a scrolling update!

With a profiler I have found that the DataBind() call takes about 1.5 seconds. The other calls are negligible.

How can I make this faster?

  • Should I use another type than ObservableCollection? An array probably?
  • Should I use another form of data binding?
  • Is there some tweak for the MSChart that I may have missed?
  • Should I use a sparsed set of date, having one value per pixel only?
  • Have I simply reached the performance limit of MSCharts?

From the type of the application to keep it "fluent", we should have multiple refreshes per second.

Thanks for any hints!

EDIT: Solution as proposed by leppie:

                this._Chart.Series[0].Points.Clear();
            foreach (var item in value) //iterates over the list of custom objects
            {
                    this._Chart.Series[0].Points.Add(new DataPoint
                    {
                        XValue = item.Index,
                        YValues = new double[] { item.Channel0Level.Value }
                    });

            }

This now works more than twice as fast!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半世蒼涼 2024-09-02 06:45:09

使用其他 Bind 方法,它们非常快。

我更新了 3 个区域的大约 15 个系列,每个系列每秒 300 分,没有真正的减速。

Use the other Bind methods, they are very fast.

I update about 15 series over 3 areas, with 300 points in every series, every second, and no real slow down.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文