[英]D3 - Can't create line chart with time data
This is my first time with D3 and I am trying to create a line chart.这是我第一次使用 D3,我正在尝试创建折线图。 I forked from this example: https://observablehq.com/@d3/line-chart
我从这个例子中分叉出来: https://observablehq.com/@d3/line-chart
My fork is here: https://observablehq.com/d/f98c480a077a03ac我的叉子在这里: https://observablehq.com/d/f98c480a077a03ac
My data looks as follows我的数据如下所示
[
{
"numAnnotations": 23,
"date": "2021-04-26"
},
{
"numAnnotations": 108,
"date": "2021-04-28"
},
{
"numAnnotations": 166,
"date": "2021-04-29"
},
...
{
"numAnnotations": 227414,
"date": "2022-04-13"
}
]
I just want to show the number of annotations increasing with date.我只想显示随日期增加的注释数量。 But I can't get the graph to render and I don't understand what I am doing wrong.
但是我无法渲染图表,而且我不明白我做错了什么。
I am assuming there is something wrong with my data format, but I can't see what's wrong.我假设我的数据格式有问题,但我看不出有什么问题。 Can someone point out my mistake?
有人可以指出我的错误吗?
I figured it out.我想到了。 The error was that I was not converting date strings to JS data objects.
错误是我没有将日期字符串转换为 JS 数据对象。 I have now fixed the code.
我现在已经修复了代码。
Here is the updated observable: https://observablehq.com/d/f98c480a077a03ac这是更新后的 observable: https://observablehq.com/d/f98c480a077a03ac
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.