所有滴答值都没有显示在X轴上

时间:2016-05-14 08:28:18

标签: d3.js nvd3.js

我正在制作像这样的堆叠多图表条形图

http://nvd3.org/examples/multiBar.html

直到现在我能够在Y轴和X轴上推动我的值,但我面临的问题是所有的值都没有显示在x轴上,但只显示了10个值。我在我的角度代码中使用nvD3库。并在x轴上显示日期。

Dates coming with a gap of 3 days

  $scope.options1 = {
    chart: {
      type: 'multiBarChart',
      height: 600,
      margin: {
    top: 20,
    right: 20,
    bottom: 200,
    left: 45
      },
      clipEdge: false,
      duration: 500,
      stacked: true,
      groupSpacing: 0.1,
      useInteractiveGuideline: true,
      showMaxMin: false,
      xAxis: {
    axisLabel: 'Timeline',
    showMaxMin: false,
    tickFormat: function(d) {
    return d3.time.format('%d-%m-%y')(new Date(d))
    },
    xScale:d3.time.scale(),
    rotateLabels: '-70'
      },
      yAxis: {
    axisLabel: 'Pending Bills',
    axisLabelDistance: -20,
    groupSpacing: 0.1,
    tickFormat: function(d) {
      return d3.format(',f')(d);
    }
      }
    }
  };

使用此函数生成滴答值数组

$scope.options1.chart.xAxis.tickValues = function() {
      var xTick = _.map(data.data.data[0].values, function(value) {
    return value.x;
      });
      xTick = _.sortBy(xTick, function(date){ return new Date(date); });
      console.log(xTick);
      return xTick;
    }

console.log(xTick)的输出类似于所有日期 -

  

[“2015-09-01”,“2015-09-02”,“2015-09-03”,“2015-09-04”,“2015-09-05”,   “2015-09-06”,“2015-09-07”,“2015-09-08”,“2015-09-09”,“2015-09-10”,   “2015-09-11”,“2015-09-12”,“2015-09-13”,“2015-09-14”,“2015-09-15”,   “2015-09-16”,“2015-09-17”,“2015-09-18”,“2015-09-19”,“2015-09-20”,   “2015-09-21”,“2015-09-22”,“2015-09-23”,“2015-09-24”,“2015-09-25”,   “2015-09-26”,“2015-09-27”,“2015-09-28”,“2015-09-29”,“2015-09-30”,   “2015-10-01”,“2015-10-02”,“2015-10-03”,“2015-10-04”,“2015-10-05”,   “2015-10-06”,“2015-10-07”,“2015-10-08”,“2015-10-09”,“2015-10-10”,   “2015-10-11”,“2015-10-12”,“2015-10-13”,“2015-10-14”,“2015-10-15”,   “2015-10-16”,“2015-10-17”,“2015-10-18”,“2015-10-19”,“2015-10-20”]

我尽可能多地读到它。所有日期都应该在x轴上绘制,但它们不是

2 个答案:

答案 0 :(得分:1)

如果要在X轴上显示所有刻度,可以将此选项添加到图表选项中:

"reduceXTicks": false,

对于扩展选项页面,您可以访问:

Angular NVD3 - MultiBarChart

希望它有所帮助。

答案 1 :(得分:0)

chart: {
    type: 'chartType',
    xAxis: {
        ticks:8
    }
}

你可以尝试"滴答"如果要在轴上显示特定数量的刻度,则属性。