Svg NVD3.js-lineplusbar的x轴类别未正确显示

Svg NVD3.js-lineplusbar的x轴类别未正确显示,svg,d3.js,nvd3.js,Svg,D3.js,Nvd3.js,我希望轴的读数为“1x”、“2x”和“3x”。在其他图形类型中,它正确地从值中获取了x值,但这一个看起来不同。我知道是否注释掉了 .x(function(d,i) { return i }); 图形显示不再正常工作。我可以添加 chart.xAxis.tickFormat(function(d) { return d3.format(',f')(d+1)+"x" }); 但如果x轴是其他字符串,那么这是一个行不通的骗局 代码: 例如: 第页的代码: nv.addGraph(functio

我希望轴的读数为“1x”、“2x”和“3x”。在其他图形类型中,它正确地从值中获取了x值,但这一个看起来不同。我知道是否注释掉了

.x(function(d,i) { return i });
图形显示不再正常工作。我可以添加

chart.xAxis.tickFormat(function(d) { return d3.format(',f')(d+1)+"x" });
但如果x轴是其他字符串,那么这是一个行不通的骗局

代码:

例如:

第页的代码:

  nv.addGraph(function() {
     //var testdata = exampleData();
     var chart = nv.models.linePlusBarChart()
           .margin({top: 30, right: 60, bottom: 50, left: 70})
           //if this is commented out, the graph does not display properly
           .x(function(d,i) { return i });
     //this is the cheat I use to show the correct X axis
     //chart.xAxis.tickFormat(function(d) { return d3.format(',f')(d+1)+"x" });
     chart.y1Axis.tickFormat(d3.format(',f'));
     chart.y2Axis.tickFormat(d3.format(',f'));

     //forces the chart to start at 0
     // if you set this to [0,100] and your data's domain is -10 to 110, the domain will be [-10,110]
     chart.lines.forceY([0]);

     d3.select('#chart svg').datum(eval("overview_data")).transition().duration(500).call(chart);
      d3.selectAll("rect.nv-bar").style("fill", function(d, i){return i > 50 ? "red":"blue";});
     nv.utils.windowResize(chart.update);
数据:


})

我看到的唯一诀窍是,如果不需要d3.format(),就不要使用它。只要这样做:

 chart.xAxis.tickFormat(function(d) { return (d+1)+"x" });

jsFiddle:

@chris-这是我的骗局。:)如果x值更改为类似“星期一”的值,它将不起作用

我能够计算出,我可以将索引馈送到我的数据对象,以提取正确的值

chart.xAxis.tickFormat(function(d) {return overview_data[0].values[d].x; });
chart.xAxis.tickFormat(function(d) {return overview_data[0].values[d].x; });