gpt4 book ai didi

javascript - Dimple.js 条长度

转载 作者:行者123 更新时间:2023-12-02 14:56:02 24 4
gpt4 key购买 nike

我正在尝试在dimple.js上绘制一个简单的直方图

问题是这些条没有到达 x 轴,它们看起来就像漂浮在周围的小盒子。

a histogram

var svg = dimple.newSvg("body", 2024, 760);
d3.csv("data/data.csv", function(d){
data = d.filter(function(x){return x['Origin'] == 'AK' && x['Year'] == '2006'});
for(i=0;i<data.length;i++){
data[i]['Count'] = +data[i]['Count']
}
console.log(data[10])

chart = new dimple.chart(svg, data);
chart.addCategoryAxis("x", ["Destination"]);
chart.addCategoryAxis("y", ["Count"]);
chart.addSeries(null, dimple.plot.bar);
chart.draw();

我的数据是这样的行数组:

Object { Year: "2006", Origin: "AK", Destination: "OH", Count: 68 }

如何让它看起来像直方图?我想查看条形的完整长度。

谢谢

最佳答案

您应该更改 y 轴的类型(从“类别”更改为“度量”):

...
chart = new dimple.chart(svg, data);
chart.addCategoryAxis("x", ["Destination"]);
chart.addMeasureAxis("y", ["Count"]);
chart.addSeries(null, dimple.plot.bar);

请参阅不同轴类型的凹坑文档:

关于javascript - Dimple.js 条长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35796014/

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