[英]Minimum zoom scale of one day for date axis in Plotly.js
Is there a way to restrict the minimum zoom of plotly chart to one day? 有没有一种方法可以将绘图图表的最小缩放限制为一天?
In the tickformat
of xaxis
, I specified %d %b
to show only day and month. 在tickformat
的xaxis
,我指定%d %b
仅显示日期和月份。 If you zoom too much, the chart will show multiple ticks for one day. 如果缩放太大,则图表将在一天中显示多个刻度。 I know plotly
tries to zoom the axes further on the bases of time but that is not required in my case. 我知道可以plotly
尝试进一步缩放轴,但是在我的情况下这不是必需的。
I have tried using tickvals
and ticktexts
but ended up having too many overlapping ticks as trace's x array can have values from 0 to 365 days. 我曾尝试使用tickvals
和ticktexts
但是由于跟踪的x数组的值可能在0到365天tickvals
, ticktexts
最终出现了太多重叠的滴答声。
var trace1 = { x: ['2000-01-01', '2000-01-02', '2000-01-03', '2000-01-04', '2000-01-05', '2000-01-06', '2000-01-07', '2000-01-08', '2000-01-09', '2000-01-10', '2000-01-11', '2000-01-12', '2000-01-13', '2000-01-14', '2000-01-15', '2000-01-16', '2000-01-17', '2000-01-18', '2000-01-19', '2000-01-20', '2000-01-21', '2000-01-22', '2000-01-23', '2000-01-24', '2000-01-25', '2000-01-26', '2000-01-27', '2000-01-28', '2000-01-29', '2000-01-30', '2000-01-31'], y: [4.3, 8.2, 4.1, 5.6, -3, -0.2, 0.3, 0.4, 4.1, 5, 4.6, -0.2, -8.5, -9.1, -2.7, -2.7, -17, -11.3, -5.5, -6.5, -16.9, -12, -6.1, -6.6, -7.9, -10.8, -14.8, -11, -4.4, -1.3, -1.1], mode: 'lines', type: 'scatter', name: '2000' }; var data = [ trace1 ]; var layout = { xaxis: { type: 'date', title: 'January Weather', tickformat: '%d %b' }, yaxis: { title: 'Daily Mean Temperature' }, title:'2000 Toronto January Weather' }; Plotly.plot('myDiv', data, layout);
<head> <script src="https://cdn.plot.ly/plotly-latest.min.js"></script> </head> <div id="myDiv" style="width:100%;height:400px;"></div>
I want to have single tick for a day on maximum zoom possible. 我想在最大缩放范围内一天打一个勾。 Is there a way to either restrict the zoom or to show at max one tick per day? 有没有办法限制缩放或每天最多显示一次刻度?
Thanks! 谢谢!
看起来最好的方法是使用type: 'category'
而不是type: 'date'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.