gpt4 book ai didi

javascript - D3.js折线图,x轴有任意日期,但想按顺序显示它们

转载 作者:行者123 更新时间:2023-11-28 13:16:31 28 4
gpt4 key购买 nike

我有一个折线图。 x 轴有日期,但它们不是按正常分布的(没有午餐或周末的数据),但我想按顺序显示它们。示例数据和我的示例图表如下,我不希望我的图表显示没有数据的时间直线,它应该从上一个日期继续。

我使用x = d3.time.scale().range([0, width])来绘制x线。有什么想法吗?

x         y
10:00:00 4
10:10:00 5
10:20:00 3
10:30:00 2
10:40:00 5
10:50:00 3
14:30:00 6
14:40:00 7

enter image description here

最佳答案

并且序数比例就可以解决问题。尝试这样的事情:

x = d3.time.scale().range([0, width]) 替换为以下内容:

var x = d3.scale.ordinal()
.domain(data.map(function(d) {
return d.date;
}))
.rangeRoundBands([0, width], 0.1);

关于javascript - D3.js折线图,x轴有任意日期,但想按顺序显示它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37453610/

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