Skip to content Skip to sidebar Skip to footer

X Axis Date Format Dygraph

i am trying to format axis date data to make it show the year also but nothing happened i am using dygraph-combined.js document.getElementById('graphdiv'), // CSV or path to a CSV

Solution 1:

Because all of your dates fall in the same month, dygraphs has decided that showing the year would be superfluous. To override this, you'll need to format the date yourself:

g = new Dygraph(document.getElementById("graphdiv"),
    "Date,Temperature\n" +
    "2014-05-07,75\n" +
    "2014-05-15,70\n" + 
    "2014-05-23,80\n"+
    "2014-05-30,72\n" ,{ 
      axes: {
        x: {
          axisLabelFormatter: function(d, gran) {
              var d = new Date(d.getTime() + 7200*1000);
              return d.strftime("%Y-%m-%d");
          }
        }
      }
    });

See fiddle here. Note that Date.strftime() is not standard—it's only available because dygraphs includes strftime.js. This may change in the future, in which case you'll need to include the library yourself or format the date in another way.


Post a Comment for "X Axis Date Format Dygraph"