Search code examples
javascriptdygraphs

How do I chart the a second custom data point in Dygraphs?


I'm toying around with Dygraphs and really liking it. However I'm having trouble setting a string value for the second point. I've tried to produce it to be a date, but I would rather keep the custom format for my own date and time.

My simple chart is

new Dygraph(document.getElementById("graphdiv"),

            dataload
          ,

          {
            labels: [ "x", "A" ],
            title: 'Point',
            ylabel: 'Value in Eng Units',
            xlabel: 'Time & Date'
          });

The code that provides the data into dataload is

i = 0
while ( i < 100){

datappointvalue = [ archivetime[i], archivevalue[i] ]  ;    
dataload.push(datapidvalue);
}

As you can guess archivetime and archivevalue are arrays that I populate. archivetime has the format of a string "22-MAR-2016 20:20:41.26" archivevalue has the format of decimal/int "144.32".

My graph always comes out like this - It will always get the values of archivevalue, but never archivetime.

So the question is ultimately how can I display my second value to be the date and time. I would prefer not having to reformat my archivedate into something else, but if necessary that can be done.

Thanks!


Solution

  • I've figured it out.

    I did not realize that the x-axis had to be in a specific date format and to use new Date() in the code.

    So my code is now

    i = 0
    while ( i < 100){
    
    datappointvalue = [ new date(archivetime[i]), archivevalue[i] ]  ;    
    dataload.push(datapidvalue);
    }
    

    where archivetime[i] now has the format "2016/3/17 20:20:41" as specified in http://dygraphs.com/data.html

    Thanks