多梳图与nvd3 / D3只示出了用于在x轴每隔一个刻度标记。我怎样才能让他们都显示出来?出了、刻度、每隔、标记

2023-09-13 02:54:49 作者:凉透心怎能重来

数据:

nvd3TestData = [
      {
        values:[
          {x:"M",y:1},
          {x:"T",y:2},
          {x:"W",y:3},
          {x:"R",y:3},
          {x:"F",y:4},
          {x:"S",y:5},
          {x:"U",y:6}
        ],
        key:"Apples"
      },
      {
        values:[
          {x:"M",y:5},
          {x:"T",y:2},
          {x:"W",y:6},
          {x:"R",y:8},
          {x:"F",y:2},
          {x:"S",y:4},
          {x:"U",y:1}
        ],
        key:"Zebras"
      }
    ]

创建图表(从angularjs指令拉):

Creating the chart (pulled from an angularjs directive):

nv.addGraph - >    图= nv.models.multiBarChart()      .stacked(真)      .showControls(假)

nv.addGraph -> chart = nv.models.multiBarChart() .stacked(true) .showControls(false)

chart.xAxis
  .axisLabel(attrs.xAxisLabel)

chart.yAxis
  .axisLabel(attrs.yAxisLabel)
  .tickFormat(d3.format(',r'))


console.log element


d3.select(element[0].children[0])
  .datum(nvd3TestData)
  .call(chart)

nv.utils.windowResize(chart.update)

输出:

预计产量将拥有所有7标签:一二W R五六U

Expected output would have all 7 labels: M T W R F S U

推荐答案

我看着nvd3.org,找不到任何实际的文档,但检查源,我发现https://github.com/novus/nvd3/blob/master/src/models/multiBarChart.js这表明reduceXTicks的布尔图参数,指示,将你想要做什么评论。我尝试过了的例子的图表之一,它的工作。具体来说,我用:

I looked on nvd3.org and couldn't find any real documentation, but checking the source, I found https://github.com/novus/nvd3/blob/master/src/models/multiBarChart.js which showed a boolean chart parameter of "reduceXTicks" with a comment indicating it would do what you want. I tried it out with one of the example charts and it worked. Specifically, I used:

chart
   .reduceXTicks(true)