After loading UTC data, Dygraph axis dates are too long and won't adjust

ⅰ亾dé卋堺 提交于 2019-12-24 03:42:38

问题


I'm feeding Dygraph some nice unix epoch data, and it's showing the axes like this:

I can't get it to be more terse and dynamically adjusted, after much fiddling. Here's my code:

var graph = new Dygraph(
           document.getElementById('plot' + formNum),
           fileURL, // path to CSV file
            {
                legend:'always',
                title: "Activity of " + station + ".BK." + fullChannel + dateString,
                valueParser: function(x){
                    return x*1000;
                },
                ticker: Dygraph.dateTicker
            }

Why are they so long? How can I change them and still take advantage of Dygraph's features that choose the level of detail on the label (i.e., no month listed on an hour's worth of data) depending on the time interval?

Here's some data:

1420498200.06954,425
1420498201.06954,425
1420498202.06954,424
1420498203.06954,425
1420498204.06954,425
1420498205.06954,425
1420498206.06954,426
1420498207.06954,426

Thoughts?


回答1:


When you override xValueParser (I'm not sure what valueParser is), you bypass dygraphs' logic for determining the type of the x-axis. Unfortunately, there's no master switch to say "this is a date axis" or "this is a numeric axis" so, if you want to go down this road, you'll have to specify all the formatters yourself:

new Dygraph(div, data, {
    ticker: Dygraph.dateTicker,
    axes: {
        x: {
            axisLabelFormatter: Dygraph.dateAxisLabelFormatter,
            valueFormatter: Dygraph.dateValueFormatter
        }
    }
})

See this demo for a fully-worked example.



来源:https://stackoverflow.com/questions/27828513/after-loading-utc-data-dygraph-axis-dates-are-too-long-and-wont-adjust

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