MSChart 滚动条实现 +绘图

发布于 2024-10-18 16:34:17 字数 1459 浏览 2 评论 0原文

我的 Windows 窗体中有一个 MSCHart 控件,用 C# 编码。基本上我有一组数据来填充图表。我需要对这些进行以下操作:

1)在 10 秒帧内阅读图表 2) 在每 10 秒帧中,我需要每秒从数组中绘制 170 个数据项。并且这种情况会一直持续到最后。

抱歉,我知道这听起来有点冗长,但我已尽力实现这一点,但我得到的结果只是失败。

如果有人可以帮助我阐明这一点,我将不胜感激。

这是我到目前为止所做的一个片段

    #region SetupChart()
    public bool SetupChart()
    {
        try
        {
            //Here is where I create the chart scale to show frames of 10 secs
            this.view.chart.ChartAreas[0].AxisX.ScaleView.Size = 10;
            return true;
        }
        catch { return false; }

    }
    #endregion

    #region Draw()
    public bool Draw()
    {
        try
        {
            view.Data = this.dllCall.GetData(1);

            int startSecond = 0;
            foreach (Int16 item in view.Data)
            {
              //Here is where I read each element from my array, unsure how to plot 170 per second :S
              this.view.chart.Series["MySeries"].Points.AddXY(startSecond, item);
    startSecond++;

            }
            return true;
        }
        catch (Exception ex)
        {
            this.ErrorMessage = ex.Message;
            return false;
        }
    }

,正如您从上面的代码中看到的,我已经让图表在开始时以 10 秒的帧显示,但在设计视图中,滚动条没有出现在我的图表下方,我无法弄清楚如何实现滚动条以显示下一个 10 秒帧,目前当我单击滚动时,它以 1 秒为步长,所以在开始时为 0 - 10,单击滚动,为 1 - 11。我 我想要它,所以当我单击滚动时,它会从 0-10 变为 10 - 20。

我提到的其他问题是每秒显示 170 个数据样本,

请有人可以在我自己的代码之上向我展示示例代码,以向我展示这是如何实现的实施我将不胜感激,提前非常感谢!

I have an MSCHart control in my windows Form, coding in C#. Basically I have an array of Data to populate the chart. I was needing to do the following with these:

1) Read the chart in 10 second frames
2) In each 10 second frame I need to plot 170 data items per second from my array. and this would continue to the end.

Sorry I know this sounds a bit lengthy but I have tried my best to implement this and the result I get back is just fail.

If anyone could please help shed some light on this for me I would greatly appreciate it.

here is a snipplet of what I done so far

    #region SetupChart()
    public bool SetupChart()
    {
        try
        {
            //Here is where I create the chart scale to show frames of 10 secs
            this.view.chart.ChartAreas[0].AxisX.ScaleView.Size = 10;
            return true;
        }
        catch { return false; }

    }
    #endregion

    #region Draw()
    public bool Draw()
    {
        try
        {
            view.Data = this.dllCall.GetData(1);

            int startSecond = 0;
            foreach (Int16 item in view.Data)
            {
              //Here is where I read each element from my array, unsure how to plot 170 per second :S
              this.view.chart.Series["MySeries"].Points.AddXY(startSecond, item);
    startSecond++;

            }
            return true;
        }
        catch (Exception ex)
        {
            this.ErrorMessage = ex.Message;
            return false;
        }
    }

As you can see from my above code, I have got the chart to show in a 10 sec frame at the beginning, but in design view the scroll bar does not appear below my chart, I cant figure out how to implement the scroll bar to show the next 10 sec frame, currently when I click to scroll it does it in steps of 1 second, so at the beginning its 0 - 10, click scroll, its 1 - 11. I wanted it so when I click the scroll it would go from 0-10 to 10 - 20.

Other problem I mentioned is showing 170 data samples per second,

Please if someone could show me example code ontop of my own to show me how this could be implemented I would greatley appreciate it, Thank you so much in advance!

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

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

发布评论

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

评论(1

日暮斜阳 2024-10-25 16:34:17

我认为cheedep的评论是正确的。以下是我将如何修改您的代码来做到这一点。您需要将 AxisScrollBarClicked 事件连接到图表。

    #region SetupChart()
    public bool SetupChart()
    {
        try
        {
            //Here is where I create the chart scale to show 170 data points
            this.view.chart.ChartAreas[0].AxisX.ScaleView.Size = 170;
            return true;
        }
        catch { return false; }

    }
    #endregion

    #region Draw()
    public bool Draw()
    {
        try
        {
            view.Data = this.dllCall.GetData(1);

            int startSecond = 0;
            foreach (Int16 item in view.Data)
            {
                this.view.chart.Series["MySeries"].Points.AddXY(startSecond, item);
                startSecond++;

            }
            return true;
        }
        catch (Exception ex)
        {
            this.ErrorMessage = ex.Message;
            return false;
        }
    }

    private void chart_AxisScrollBarClicked(object sender, System.Windows.Forms.DataVisualization.Charting.ScrollBarEventArgs e)
    {
        if (e.Axis == chart.ChartAreas[0].AxisX)
        {
            if (e.ButtonType == System.Windows.Forms.DataVisualization.Charting.ScrollBarButtonType.SmallIncrement)
                chart.ChartAreas[0].AxisX.ScaleView.Position += 170;
            else if (e.ButtonType == System.Windows.Forms.DataVisualization.Charting.ScrollBarButtonType.SmallDecrement)
                chart.ChartAreas[0].AxisX.ScaleView.Position -= 170;
        }
    }

I think cheedep's comment is correct. Here is how I would modify your code to do it. You will need to hook up the AxisScrollBarClicked event to your chart.

    #region SetupChart()
    public bool SetupChart()
    {
        try
        {
            //Here is where I create the chart scale to show 170 data points
            this.view.chart.ChartAreas[0].AxisX.ScaleView.Size = 170;
            return true;
        }
        catch { return false; }

    }
    #endregion

    #region Draw()
    public bool Draw()
    {
        try
        {
            view.Data = this.dllCall.GetData(1);

            int startSecond = 0;
            foreach (Int16 item in view.Data)
            {
                this.view.chart.Series["MySeries"].Points.AddXY(startSecond, item);
                startSecond++;

            }
            return true;
        }
        catch (Exception ex)
        {
            this.ErrorMessage = ex.Message;
            return false;
        }
    }

    private void chart_AxisScrollBarClicked(object sender, System.Windows.Forms.DataVisualization.Charting.ScrollBarEventArgs e)
    {
        if (e.Axis == chart.ChartAreas[0].AxisX)
        {
            if (e.ButtonType == System.Windows.Forms.DataVisualization.Charting.ScrollBarButtonType.SmallIncrement)
                chart.ChartAreas[0].AxisX.ScaleView.Position += 170;
            else if (e.ButtonType == System.Windows.Forms.DataVisualization.Charting.ScrollBarButtonType.SmallDecrement)
                chart.ChartAreas[0].AxisX.ScaleView.Position -= 170;
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文