开发者

MSChart scroll bar implementation + plotting

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 co开发者_运维问答uld 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!


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;
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜