数据更改时更新 Telerik 图表

发布于 2025-01-04 11:38:38 字数 1874 浏览 1 评论 0原文

我有一个缓冲区列表,我将其显示到 Telerik radchart 中。 它显示正确,但当一个(或多个)缓冲区更新时,我想更新图表以反映新状态。 我唯一能做的就是从头开始重新创建图表,这是一个非常简单的解决方案,但不是很聪明...... 所以我的问题是,是否有一种特殊的 RadChart 类型或某些选项可以设置为在映射为 DataSeries 的集合之一发生更改时使图表自动更新。 有人可以帮忙吗?

这是我用来创建图表的代码:

private void createChart()
    {
        //Set axis stuff and clear old configuration here

            //Create a dataseries for each values to draw
           foreach (ChannelKeyValueConfiguration channelKeyValue in this.Device.Configuration.ChannelConfigurations)
                {

                    IChannel channel = this.Device.Channels[channelKeyValue.Name];

                    DataSeries serie = new DataSeries();
                    serie.Definition = new LineSeriesDefinition();
                    serie.LegendLabel = channel.Description;

                    int i = 0;
                    int elNumber = channel.Measure.Buffer.Count;   //Neeeded to set xAxis values
                    DateTime minTime = channel.Measure.TimeStamp.Value.AddMilliseconds(-1 * elNumber * channel.Measure.PollingTime);   //Neeeded to set xAxis values

                    foreach (double point in channel.Measure.Buffer)   //Buffer is a Queue<T> that i use as data provider. It updates each x seconds.
                    {
                        i++;
                        serie.Add(new DataPoint() { XValue = minTime.AddMilliseconds( i * channel.Measure.PollingTime).ToOADate(), YValue = point });
                    }

                    RadTimeChart.DefaultView.ChartArea.DataSeries.Add(serie);
                }
            }

然后我有一个应该更新图表的事件处理程序。因为我不知道如何实现它,所以它只是重新创建它以便更新它。

void StatusChanged(object sender, EventArgs e)
    {
        Dispatcher.BeginInvoke(new Action(delegate
        {
            createChart();
        }));
    }

请提供一些关于我如何更好地处理更新的想法。 提前致谢!

i have a list of buffers that i display into a telerik radchart.
It displays correctly but when one (or more) of the buffers gets updated i want to update the chart to reflect the new state.
The only thing i'm able to do is recreating the chart from scratch that is a very simple solution yet not very clever...
So my question is if there is a special RadChart type or some option to set to get the chart to autoupdate when one of the collection mapped as DataSeries changes.
Anyone can help?

Here is the code i use to create the chart:

private void createChart()
    {
        //Set axis stuff and clear old configuration here

            //Create a dataseries for each values to draw
           foreach (ChannelKeyValueConfiguration channelKeyValue in this.Device.Configuration.ChannelConfigurations)
                {

                    IChannel channel = this.Device.Channels[channelKeyValue.Name];

                    DataSeries serie = new DataSeries();
                    serie.Definition = new LineSeriesDefinition();
                    serie.LegendLabel = channel.Description;

                    int i = 0;
                    int elNumber = channel.Measure.Buffer.Count;   //Neeeded to set xAxis values
                    DateTime minTime = channel.Measure.TimeStamp.Value.AddMilliseconds(-1 * elNumber * channel.Measure.PollingTime);   //Neeeded to set xAxis values

                    foreach (double point in channel.Measure.Buffer)   //Buffer is a Queue<T> that i use as data provider. It updates each x seconds.
                    {
                        i++;
                        serie.Add(new DataPoint() { XValue = minTime.AddMilliseconds( i * channel.Measure.PollingTime).ToOADate(), YValue = point });
                    }

                    RadTimeChart.DefaultView.ChartArea.DataSeries.Add(serie);
                }
            }

Then i have an event handler that should update the chart. As i don't know how to achieve it it just recreates it so that it is updated.

void StatusChanged(object sender, EventArgs e)
    {
        Dispatcher.BeginInvoke(new Action(delegate
        {
            createChart();
        }));
    }

Please provide some idea on how i can handle updates better.
Thanks in advance!

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

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

发布评论

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

评论(1

与他有关 2025-01-11 11:38:38

经过大量搜索和测试,我发现 Telerik 的图表速度很慢,如果您不使用队列来绘制图表,有时使用的内存会开始持续增加。
不过,他们确实在他们的网站中提供了一些非常好的示例,例如实时数据示例,这正是我正在寻找的。

After a lot of searching and tests i found out that telerik's charts are slow and sometimes used memory start to increse costantly if you do not use Queue to drw your chart.
However they do give some very good examples in their site, like the Live Data example, that is pretty much what i was looking for.

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