您在 plnkr 上引用了旧版本的 nvd3。有一个文档和一个新版本 1.7.x - 许多图表都在使用共享库,因为尤其是 multiChart 是错误的。
而且你没有很好地搜索,已经有一些关于这个的问题。
所以你的问题试试
chart
.yDomain1([0,200])
.yDomain2([0,10]);
我无法得到 s.th。就像为 xAxis 工作一样。但我读到,如果它适用于折线图、条形图或堆积面积图,并不是所有的都适用于 multiChart,所以这可能是问题所在。
帖子:
nvd3-multi-bar-horizontal-chart-x-axis-domain
change-range-for-one-y-axis-nvd3-d3
how-can-i-specify-a-domain-x-axis-in-nvd3-linechart
更新:这是我在正在运行且在 nvd3 1.7 中运行的 multiChart 上的代码的一部分(但由于我从 1.1 更新了它,因此可能有一些不推荐使用的符号):
nv.addGraph(function() {
var chart = nv.models.multiChart()
.yDomain1([-20, 80])
.yDomain2([-50, 200]) //important! works only with manual tickValues definiton (see chart1.yAxis2.tickValues([...]) !)
.margin({top: 30, right: 75, bottom: 40, left: 70}) //important for display of lable on y2Axis!
;
//chart option settings
var options = {
showControls: false,
showLegend: true
}
chart1.options(options);
d3.json(filepath, function(error, json) {
if (error) {
return console.warn(error);
}
var _inputdata = json.map(function(series) {
series.values = series.values.map(function(d) {
return { x: d[0], y: d[1] }
});
series.key = series.key.map(function(d) {
return d[lang]
});
return series;
});
chart1.xAxis
.axisLabel("Date")
.tickFormat(function(d) { return (d3.time.format('%d.%m. %H:%M')(new Date(d))) })
;
chart1.yAxis1
.axisLabel('leftAxis')
.axisLabelDistance(10)
.tickFormat(d3.format('.2f'))
;
chart1.yAxis2
.axisLabel('rightAxis')
.tickFormat(d3.format('.2f'))
//(problem is, nvd3 does always tickValues of 20 and then jumps to tickVlaues of 50).
//not possible to set fixed steps of ticks like "y2ticks(10), workaround (-50 til 200):"
.tickValues([-50,-25,0,25,50,75,100,125,150,175,200])
;
d3.select('#chart_1').append("svg")
.attr("id", "chart1")
.attr("height", 500)
.datum(_inputdata)
.transition()
.duration(300)
.call(chart1)
;
nv.utils.windowResize(function() {
chart1.update();
});
//update chart to correct alignments of objects (e.g. wrapping o. elements)
chart1.update();
});
});