Menu

Plots are not plotting correctly or don't show up when using the Date option for the Xaxis from Zedgraph

Help
Tom
2013-06-14
2019-09-21
  • Tom

    Tom - 2013-06-14

    This is a little long, but hopefully I can make my point here. I’m reading in humidity data from a device, and the reading part works fine. I developed a zedgraph program that plots the points as they are read into the program (in real time). I’m using the RollingPointPairList and converted everything to seconds, and everything works fine (the time scale in the x-axis is in seconds, from 0 to 30).
    Now, I decided that it would be more appropriate to show on the x-axis the date and time as opposed to seconds, and this is what is not working correctly. Documentation seems to be sparse on describing some of the functionality of some of the statements in zedgraph, and so I decided to post the problem here. Here are just snippets of the code, but enough to make my point (parts of the critical part of the code are listed):

    Private void ReadRelativeHumidity()
    {
    GraphPane ReadHumidity = zedGraphControl1.GraphPane;

    Rolling PointPairList ListH – new PointPairList()
    Timer3.interval = 50;

    Double start_date = System.DateTime.Now.ToOADate();
    Double end_date = System.DateTime.Now.AddSeconds(30).ToOADate();
    ReadHumidity.XAxis.Scale.Min = new ZedGraph.XDate(start_date);
    ReadHumidity.XAxis.Scale.Max = new ZedGraph.XDate(end_date);
    ReadHumidity.XAxis.Scale.MinorStep = 1;
    ReadHumidity.XAxis.Scale.MajorStep = 5;
    ReadHumidity.XAxis.Type = ZedGraph.AxisType.Date;
    ReadHumidity.XAxis.Scale.Format = "dd:MM HH:mm:ss";
    ReadHumidity.XAxis.Scale.MajorUnit = ZedGraph.DateUnit.Minute;
    ReadHumidity.XAxis.Scale.MinorUnit = ZedGraph.DateUnit.Second;

             /* Below works when you comment the above and uncomment below */
        /*ReadHumidity.XAxis.Scale.Min = 0;
              ReadHumidity.XAxis.Scale.Max = 30;  //this value was 30, controls speed in seconds
              ReadHumidity.XAxis.Scale.MinorStep = 1;
              ReadHumidity.XAxis.Scale.MajorStep = 5; */
    

    }

    Private void timer3_tick(…)
    {
    double time = (Environment.TickCount - tickStart) / 1000.0;

    listHum.Add(time, Hum); //plot the points

            if (time > xScale.Max - xScale.MajorStep)
            {
    
                 xScale.Max = time + xScale.MajorStep;
                //xScale.Min = xScale.Max - (Tmin + 30);
                xScale.Min = xScale.Max - 30.0;
    
             }
    

    }

    The variable “Hum” is read in from an SNMP device, so that is being read in correctly. (As a side note, if I uncomment the commented part of the code above and comment the one involving the date part, the code runs fine – I added that just to show that there are no issues with doing it this way using Scale.Min =0 and Scale.Max = 30).
    Now, back to the interjecting the date on the xaxis: the start and end date delta is 30 seconds (according to what I can understand from documentation from above using the “AddSeconds (30)”). The “time” variable above starts off at zero using the timer in C# (which I think is my problem here), and the “if( time>… )” statement helps in the rolling of the points. When I print out start_date and end_date, they are large numbers, such as 41439.492… and 41439.491… . It seems like when I subtract these, they are not 30 secs apart (something like .00034?). Also, no points are plotted because the time “time” starts off at zero, and it appears that the start date on the plot itself starts off at 41439.492…, I’m guessing . At this point, I decided to use this large number as an offset, and by doing this, the date/time on the axis turn to all 00:00 and the points plotted start plotting somewhere in the middle. I hope I explained my problem correctly. Is there anyone out there with any insight of translating the date to the correct offset so the points start plotting from the beginning of the plot and scroll from left to right, and at the same time, update the date correclty as the xaxis scrolls. Appreciate any help. Thanks.

     
  • Tom

    Tom - 2013-06-14

    Also, wanted to say that I did it this way as well with the same results as in my previous post:

             ReadHumidity.XAxis.Type = AxisType.Date;
             ReadHumidity.XAxis.Scale.Format = "HH:mm:ss";
             ReadHumidity.XAxis.Scale.Min = new XDate(DateTime.Now);
             ReadHumidity.XAxis.Scale.Max = new XDate(DateTime.Now.AddSeconds(30));
             ReadHumidity.XAxis.Scale.MinorUnit = DateUnit.Second; //second
             ReadHumidity.XAxis.Scale.MajorUnit = DateUnit.Minute;  //minute
             ReadHumidity.XAxis.Scale.MinorStep = 1;
             ReadHumidity.XAxis.Scale.MajorStep = 5;
    
     
  • Tom

    Tom - 2013-06-17

    Never mind, figured it out. Apparently there is a bug in Zedgraph - when using the Date (i.e., AxisType.Date) option, the display jumps as opposed to having a smooth update rate. I've seen this is a problem with others, and apprently there is no fix as far as I can research.

     
  • Andy

    Andy - 2019-09-20

    Hi Tom, have you been fixed the problem...?
    Cause I have same problems..

     
  • John Vickers

    John Vickers - 2019-09-21

    Andy,

    Take a look at my sample project that demonstrates how to display live data on a scrolling graph with timestamps correctly that don't jump. I suspect it is exactly what you are trying to do.
    https://github.com/jgvicke/ZedGraph_SineWave

    By the way Tom's posts were from 2013. On posts that old you are better off starting a new thread instead of tacking onto an old one.

    John

     

Log in to post a comment.

MongoDB Logo MongoDB