admin管理员组文章数量:1332352
I would like to control the x-axis intervals that are shown (and the vertical gridlines associate with each label point) but I have been unable to find way to do this. Dygraphs fills in x labels based on the over all x range by default, but I want more granularity. For instance if I want to present a month worth of data for July'14, I use dateWindow to set my bounds. By default Dygraphs gives me x intervals at 7/6, 7/13, 7/20, and 7/27 (the start of each week). But I want more labels and corresponding vertical lines; every 3 days for instance, instead of week start.
Is this possible? I'm happy with how each x label is displayed (so I don't think it's label formatter). I just want more of them.
I would like to control the x-axis intervals that are shown (and the vertical gridlines associate with each label point) but I have been unable to find way to do this. Dygraphs fills in x labels based on the over all x range by default, but I want more granularity. For instance if I want to present a month worth of data for July'14, I use dateWindow to set my bounds. By default Dygraphs gives me x intervals at 7/6, 7/13, 7/20, and 7/27 (the start of each week). But I want more labels and corresponding vertical lines; every 3 days for instance, instead of week start.
Is this possible? I'm happy with how each x label is displayed (so I don't think it's label formatter). I just want more of them.
Share Improve this question asked Aug 25, 2014 at 13:24 user2245759user2245759 4671 gold badge6 silver badges18 bronze badges3 Answers
Reset to default 4Nowadays there's an exposed method named getDateAxis
at Dygraph instance.
Find more info about it at dygraph-tickers.js
.
If you want to, you can also start reading since datePicker
So, you can treat your wanted "frequency" (each 3 days, each 1 day), based on maximum
and minimum
values of x-axis.
My example below won't find the "best frequency", but instead will fix it to ALWAYS show a tick each HOUR.
For testing purposes, change Dygraph.HOURLY
to Dygraph.TWO_DAILY
and you'll have a tick each two days, no matter what zoom you're in.
g = new Dygraph(
document.getElementById("graphdiv"),
graph_data,
{ // other options......
axes: {
x: {
ticker: function(min, max, pixels, opts, dygraph, vals) {
return Dygraph.getDateAxis(min, max, Dygraph.HOURLY, opts, dygraph);
},
},
}
}
);
Change this section in the actual dygraph-bined.js file (2327):
x: {
pixelsPerLabel: 70, <----- change this value!!
axisLabelWidth: 60,
axisLabelFormatter: Dygraph.dateAxisLabelFormatter,
valueFormatter: Dygraph.dateValueFormatter,
drawGrid: true,
drawAxis: true,
independentTicks: true,
ticker: null // will be set in dygraph-tickers.js
},
Changing the pixelsPerLabel
value in the options block, where the graph is set up, seems not to work. I'm not sure why.
Looks like the axis object provides the ticker property which is a function you can setup to return the tickmarks you want (http://dygraphs./options.html#Axis display).
Have a look at the Dygraphs built in ticker functions: http://dygraphs./dygraph-tickers.js
You can use these as a starting point for developing your own.
本文标签: javascriptSpecifying dygraphs x interval ticksStack Overflow
版权声明:本文标题:javascript - Specifying dygraphs x interval ticks - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742321072a2452795.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论