dyGraphs DateWindow to parse from a date to the end of the CSV

三世轮回 提交于 2019-12-10 12:23:14

问题


I am using dygraphs with a CSV file that is constantly having data added to it. I would like to use dateWindow to have it auto zoom in on a range that is from a date I specify to the end of the file when it loads. I can't make it work.

I've tried just leaving the "latest" value blank such as:

dateWindow: [Date.parse("2017/07/01 12:00:00"),],
dateWindow: [Date.parse("2017/07/01 12:00:00"), Date.parse("")],

but nothing works. Is this possible and if so can someone point me to how to do it? Thank you.


回答1:


You can retrieve the x value range with g.xAxisExtremes() once the csv data values are loaded. Then call g.updateOptions() passing dateWindow as your desired starting date and the high end of the value range. The csv file is loaded dynamically, so you'll want to set the desired range in a ready() function. Something like this:

<script type="text/javascript">
  var g = new Dygraph(
    document.getElementById("graphdiv"),
    "temperatures.csv", // path to CSV file
    {}          // options
  );
  g.ready(function () {
    var ends = g.xAxisExtremes();
    g.updateOptions({dateWindow: [Date.parse("2017/07/01 12:00:00"),ends[1]]});
  });
</script>


来源:https://stackoverflow.com/questions/45991763/dygraphs-datewindow-to-parse-from-a-date-to-the-end-of-the-csv

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