作者:子幽 | 来源:互联网 | 2023-12-10 00:19
本文介绍了如何使用n3-charts绘制以日期为x轴的数据,并提供了相应的代码示例。通过设置x轴的类型为日期,可以实现对日期数据的正确显示和处理。同时,还介绍了如何设置y轴的类型和其他相关参数。通过本文的学习,读者可以掌握使用n3-charts绘制日期数据的方法。
I have a some data that I would like to plot using n3-charts and this is what I have.
我有一些数据,我想用n3图表绘制,这就是我所拥有的。
$scope.optiOns= {
axes: {
x: {
key: "dateRecorded",
type: "date",
labelFunction: function(d) { return d3.time.format("%Y-%m-%d").parse(d); }
},
y: {type: "linear"}
},
series: [
{
y: "weight",
key: "weight",
label: "Weight",
color: "#2ca02c"
}
]
};
This is a sample piece of data that I would like to plot.
这是我想要绘制的示例数据。
[{dateRecorded: "2015-04-15", weight: 15}, {dateRecorded: 2015-04-16, weight: 16}, {dateRecorded: "2015-04-17", weight: 17}]
The chart shows up but no data is plotted. The browser console outputs the following.
图表显示但没有绘制数据。浏览器控制台输出以下内容。
TypeError: undefined is not a function
at d3_time_parseFullYear
So it cannot parse the date correctly but I am not sure what I am doing wrong.
所以它无法正确解析日期,但我不确定我做错了什么。
Any help would be appreciated.
任何帮助,将不胜感激。
2 个解决方案