gpt4 book ai didi

javascript - NVD3 如何正确设置 y 刻度?

转载 作者:行者123 更新时间:2023-11-29 15:39:04 26 4
gpt4 key购买 nike

我的累积折线图没有正确构建 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,正如您在此处看到的:

https://www.evernote.com/shard/s253/sh/35928a9c-f5bb-4862-a227-f86423e6dd8a/8745a2c6cb5571002b7ec33b5386172a

这是我的代码:

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])

最佳答案

问题解决了!

它是累积折线图,它必须在 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]
]
}];

如你所见:

https://www.evernote.com/shard/s253/sh/404834ae-1797-4d23-96bd-3f7e0674822e/ef09346d45af2b31cd122a2014c34377

附言。谢谢鲍勃

关于javascript - NVD3 如何正确设置 y 刻度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22794077/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com