问题
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