Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用C语言编写的MS图表中的时间序列#_C#_Winforms_Visual Studio 2010_Mschart - Fatal编程技术网

C# 用C语言编写的MS图表中的时间序列#

C# 用C语言编写的MS图表中的时间序列#,c#,winforms,visual-studio-2010,mschart,C#,Winforms,Visual Studio 2010,Mschart,我使用MS图表绘制时间序列中的点,如下所示 chart1.Series[0].Points.AddXY(time, voltage); 我获得了大量数据(1点/100毫秒),因此在一天结束时,程序绘制新数据的速度非常慢。因此,我希望能够在一段时间后自动滚动图表的x轴,例如30分钟左右。。。我希望将数据打印出来,但不直接显示给用户,而是隐藏在图表的左侧 我该怎么做?编辑:请参见结尾处的“我的编辑”以及放大集合的解决方案 只绘制可见的内容,不绘制其他内容。 可以将旧值保留在内存中,也可以将它们

我使用MS图表绘制时间序列中的点,如下所示

chart1.Series[0].Points.AddXY(time, voltage);  
我获得了大量数据(1点/100毫秒),因此在一天结束时,程序绘制新数据的速度非常慢。因此,我希望能够在一段时间后自动滚动图表的x轴,例如30分钟左右。。。我希望将数据打印出来,但不直接显示给用户,而是隐藏在图表的左侧

我该怎么做?

编辑:请参见结尾处的“我的编辑”以及放大集合的解决方案 只绘制可见的内容,不绘制其他内容。

可以将旧值保留在内存中,也可以将它们持久化到磁盘,并根据需要加载它们

这里有一个例子:

我的内存中有1000000个点,我可以无缝滚动并立即绘制

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public List<int> Values { get; private set; }

        public int ValuesToShow
        {
            get { return 20; }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Values = new List<int>();
            var random = new Random();
            for (int i = 0; i < 1000000; i++)
            {
                int next = random.Next(10, 50);
                Values.Add(next);
            }

            hScrollBar1.Maximum = (Values.Count - 1) - ValuesToShow;
        }

        private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            var hScrollBar = (HScrollBar) sender;
            int value = hScrollBar.Value;
            IEnumerable<int> enumerable = Values.Skip(value).Take(ValuesToShow);

            chart1.Series.Clear();
            var series = new Series();

            foreach (int i in enumerable)
            {
                series.Points.Add((double) i);
            }

            chart1.Series.Add(series);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public List<int> Values { get; private set; }

        public int ValuesToShow { get; set; }

        private void Form1_Load(object sender, EventArgs e)
        {
            ValuesToShow = 20;

            Values = new List<int>();
            var random = new Random();
            for (int i = 0; i < 1000000; i++)
            {
                int next = random.Next(10, 50);
                Values.Add(next);
            }

            hScrollBar1.Maximum = (Values.Count - 1) - ValuesToShow;

            RefreshChart();
        }

        private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            RefreshChart();
        }

        private IEnumerable<int> GetCurrentValues(int value)
        {
            return Values.Skip(value).Take(ValuesToShow);
        }

        private int GetCurrentPosition()
        {
            return hScrollBar1.Value;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ValuesToShow /= 2;
            RefreshChart();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ValuesToShow *= 2;
            RefreshChart();
        }

        private void RefreshChart()
        {
            int value = GetCurrentPosition();
            IEnumerable<int> enumerable = GetCurrentValues(value);

            chart1.Series.Clear();
            var series = new Series();

            foreach (int i in enumerable)
            {
                series.Points.Add((double) i);
            }

            chart1.Series.Add(series);
        }
    }
}
最后注释:

100万分似乎是合理的(20分钟的数据),更多,它开始放缓,我也尝试了84米,但这是不现实的

为了使其更加用户友好,您可能可以在用户使用鼠标滚轮时进行缩放


如果您能负担得起其他解决方案,您可能可以使用WPF和/或商业解决方案(如DevXPress)获得开箱即用的良好性能,但您必须为此付费。。。在这里,我为您提供了一个0美元的解决方案,它只缺少一个选择矩形,但一直都很快:D

@TaW我想这是正确的选择,除非我发布了我的答案,否则我不会看到您的评论。除了Aybe的好建议之外:Look选择矩形实际上是开箱即用的,用于缩放MS图表。