0

I have one chart, with 8 series in it. Each series has the same rate of data; which is 75 Hz samples from an instrument. I'm showing the most recent 10 seconds of data, always updating.

Some of what I have:

Definition:

    this.chart1.ChartAreas[0].AxisX.Minimum = 1;
    this.chart1.ChartAreas[0].AxisX.Maximum = 751;
    //this.chart1.Series[0].Lable = "X = (#VALX - 1)/75"; // ineffective, tried various syntax

Management of new data insertions (showing one channel example only):

    ch01_series.Points.AddY(dCh01); // ch01_series is "Series", dCh01 is double
    if(ch01_series.Points.Count > 751)
    {
        ch01_series.Points.RemoveAt(0);
    }

The main problem has been that I cannot figure out how to label my X-Axis to show 0-10.

What I'd like to see is 11 vertical gridlines labeled "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10"; Right now, the chart self labels, does not give me an end point, it shows "1, 201, 401, and 601". (Writing this I'm now thinking to find a way to control the number of gridlines and will check.)

Any suggestions on (1) how to show my labels as desired, and (2) how to customize my gridlines so that I can see 11 of them instead of the 4 which MS Chart chooses to draw. For starters I'm sure I'd be fine if I could label the X-Axis as intended regardless of the gridlines and may remove the gridlines

Some Updates:

I figured out how to set the gridline interval:

    this.chart1.ChartAreas[0].AxisX.MajorGrid.Interval = 75;

And set the X-Axis interval:

    this.chart1.ChartAreas[0].AxisX.Interval = 75;

What remains is how I get a custom label to work, or some form of label which shows 0-10 instead of "1, 76, 151, 226, 301, 376, 451, 526, 601, 676, and 751". The formula is (Xvalue - 1)/75, but the label syntax didn't accept my attempts.

rtm
  • 81
  • 1
  • 9

1 Answers1

0

This is very similar to MSChart Y-Axis and X-Axis Labelling

    chart1.Customize += chart1_Customize;

    void chart1_Customize(object sender, EventArgs e)
    {
        foreach (var label in chart1.ChartAreas[0].AxisX.CustomLabels)
        {
            int xval = int.Parse(label.Text); // get the list index
            int xnewLabel = ((xval - 1) / 75); // change the range
            label.Text = xnewLabel.ToString(); // update to new value
        }
    }
Community
  • 1
  • 1
BinaryConstruct
  • 191
  • 1
  • 5
  • Thank you very much! I mostly had it working, but in a very brute force coded method and was going to post a "Can't this be done any easier?" follow-up question. – rtm Jul 16 '13 at 20:16
  • Glad to help, mscharts occasionally do things in ways you don't expect. – BinaryConstruct Jul 16 '13 at 20:22