【问题标题】:Rickshaw only show gridlines on some points人力车仅在某些点上显示网格线
【发布时间】:2013-05-14 07:59:50
【问题描述】:

我有一张用人力车制作的图表:

我设置了刻度线,以便它们只有在值为 -24、0 或 24 时才有标签:

// Instantiate x-axis
var xAxis = new Rickshaw.Graph.Axis.X({
  graph: graph,
  orientation: 'bottom',
  pixelsPerTick: 25,
  element: graphXAxis,
  tickFormat: function(n) {
    switch(n) {
      case -24: return '24 hours ago';
      case 0: return 'Now';
      case 23: return '24 hours from now';
    }
  }
});

但是网格线出现在每一个刻度上,即使是我的案例语句没有返回的那些! 我怎样才能摆脱其余的网格线?

【问题讨论】:

    标签: javascript d3.js rickshaw


    【解决方案1】:

    您可以使用 ticks 键指定所需的刻度数。但是,这不会让您具体控制生成这些刻度的位置,并且您可能无法准确获得请求的数字。通过对 RickShaw 的一些额外扩展,您可以获得对刻度的更多控制,支持代码 here 对此进行了详细说明。

    var xAxis = new Rickshaw.Graph.Axis.X({
      graph: graph,
      orientation: 'bottom',
      pixelsPerTick: 25,
      ticks:3,
      element: graphXAxis,
      tickFormat: function(n) {
        switch(n) {
          case -24: return '24 hours ago';
          case 0: return 'Now';
          case 23: return '24 hours from now';
        }
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-01
      • 1970-01-01
      • 2013-09-03
      • 1970-01-01
      • 2016-09-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多