X axis date format dygraph

大兔子大兔子 提交于 2019-12-11 08:47:53

问题


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 file.
"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) {
                  return Dygraph.dateAxisFormatter(new Date(d.getTime() + 7200*1000), gran);
              }
            }
          }
        }
);

回答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.



来源:https://stackoverflow.com/questions/24085781/x-axis-date-format-dygraph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!