我有来自example page的以下代码片段并且仅使用正值来使用它并且它起作用。现在我有一些负值,并且y轴不再正确缩放。
取景器中的图形也只是正值,一些非常大的正值通过顶部。
var chart = nv.models.lineWithFocusChart();
var d = new Date();
chart.brushExtent([d.setHours(d.getHours() - 12), new Date()]);
chart.height(800);
chart.xAxis
//.rotateLabels(-30)
.tickFormat(function(d) {
return d3.time.format('%d.%m. %H:%M')(new Date(d));
});
chart.x2Axis
//.rotateLabels(-30)
.tickFormat(function(d) {
return d3.time.format('%d.%m. %H:%M')(new Date(d));
});
chart.yTickFormat(d3.format(',.2f'));
chart.useInteractiveGuideline(true);
d3.select('#chartWrapper').append('svg')
.datum(data)
.transition().duration(500)
.call(chart);
我试图找到最大值和最小值,并将域和范围设置为该值。这本来是静态的,但它既不起作用。
var chartY = {max: 0, min: 0};
$.each(data, function(i, e) {
if ( parseInt(e.y, 10) > chartY.max) { chartY.max = parseInt(e.y, 10); }
if ( parseInt(e.y, 10) < chartY.min) { chartY.min = parseInt(e.y, 10); }
});
chart
.yDomain([chartY.min, 0, chartY.max])
.yRange([chartY.min, 0, chartY.max]);
我有一个plnkr,也许你们有一个解决方案。 DEMO
通过以下步骤,我能够很好地显示它: