我的累积折线图未正确构建yScale。
鉴于要构建图表的数据:
var data = [{
key: "Page view",
values: [
["2013-07-01 00:00:00", 1],
["2013-08-01 00:00:00", 17],
["2013-09-01 00:00:00", 5],
["2013-10-01 00:00:00", 13]
]
}];
在yScale上显示的最大值17显示为8,如下所示:
那是我的代码:
nv.addGraph(function () {
var chart;
chart = nv.models.cumulativeLineChart()
.x(function(d) { return moment(d[0]) })
.y(function(d) { return d[1] })
.color(d3.scale.category10().range())
.transitionDuration(300)
.showControls(false);
chart.xAxis
.tickFormat(function (d) {
return d3.time.format('%d/%m/%y')(new Date(d))
});
chart.xScale(d3.time.scale());
d3.select('#chart svg')
.datum(data)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
https://gist.github.com/lemanchester/9919615
我试过用:
chart.yScale().domain([0, 50]);
或/和
chart.forceY ([0, 50])
答案 0 :(得分:1)
解决了问题!
它的累积折线图必须以Y轴上的0开始
var data = [{
key: "Page view",
values: [
["2013-06-01 00:00:00", 0],
["2013-07-01 00:00:00", 1],
["2013-08-01 00:00:00", 17],
["2013-09-01 00:00:00", 5],
["2013-10-01 00:00:00", 13]
]
}];
如你所见:
PS。谢谢鲍勃