2

I have searched some examples of ZedGraph, but I couldn't perform what I wanted. I am drawing real-time data each 20 ms, and I want to show the system time on the x-axis (using the ZedGraph class XAxis). However when I try to draw milliseconds on the x-axis I cannot see any data. Here is my code:

//X-Axis Settings
pane.XAxis.Scale.MinorStep = 1;
pane.XAxis.Scale.MajorStep = 5;
pane.XAxis.Type = AxisType.Date;
pane.XAxis.Scale.Format = "HH:mm:ss.fff";
pane.XAxis.Scale.Min = new XDate(DateTime.Now);
pane.XAxis.Scale.Max = new XDate(DateTime.Now.AddSeconds(10));
pane.XAxis.Scale.MinorUnit = DateUnit.Second;
pane.XAxis.Scale.MajorUnit = DateUnit.Second;

XDate time = new XDate(DateTime.Now.ToOADate());
for (int i = 1; i < 16; i++)
{
    listAuido.Add(time, (double)Read_Data1[i]);
}

Scale xScale1 = zgcMasterPane.MasterPane.PaneList[0].XAxis.Scale;
if (time.XLDate > xScale1.Max)
{
   xScale1.Max = (XDate)(DateTime.Now.AddSeconds(1));
   xScale1.Min = (XDate)(DateTime.Now.AddSeconds(-20));
}

Edit: This code structure is solved my problem.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Blast
  • 955
  • 1
  • 17
  • 40

1 Answers1

3

The following code is drawing all the data on the same x point!

for (int i = 1; i < 16; i++)
{
    listAuido.Add((XDate)(DateTime.Now.Millisecond), (double)Read_Data1[i]);
}

Why do you set your XAxis to the date format if you don't want it to appear like that?

OK, try this:

//Declare the x coordinate (time) variable
double xValue = 0;

//Setting the axis
pane.XAxis.Scale.MinorStep = 1;
pane.XAxis.Scale.MajorStep = 5;
pane.XAxis.Scale.Max = 0;
pane.XAxis.Scale.Min = -10;

//drawing the data
private void draw(double dataValue)
{
    LineItem curve1 = zedGraphControl1.GraphPane.CurveList[0] as LineItem;
    IPointListEdit list1 = curve1.Points as IPointListEdit;

    list1.Add(xValue*(20/1000), dataValue); //

    //Scroll
    Scale XScale = zedGraphControl1.GraphPane.XAxis.Scale as Scale;
    XScale.Max = xValue*(20/1000);
    XScale.Min = XScale.Max - 10;

    xValue++;
    zedGraphControl1.AxisChange();
    zedGraphControl1.Invalidate();
}

//Now you call the function draw every 20 ms using a [Timer][1] for example
private void timer1_Tick(object sender, EventArgs e)
{
    draw(data[xValue]);
}

By the way I am not using MasterPane here.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
chouaib
  • 2,763
  • 5
  • 20
  • 35
  • Thank you for your comment. I have solved my problem using another way. I edited my question and shared the code. – Blast Dec 14 '13 at 09:03
  • 1
    i would appreciate +1 rather than thank u ;) anyways good luck we are here to help each other and learn from each other – chouaib Dec 16 '13 at 00:34