从数据对象数组创建折线图

从数据对象数组创建折线图

本文介绍了从数据对象数组创建折线图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习D3,但在从数据对象数组创建简单的线图时遇到了问题.

I'm trying to learn D3 and am having problems creating a simple line graph from an array of data objects.

我有一个看起来像这样的数据对象数组...

I have an array of data objects that look like this...

[
    {date: "03/04/15", rain: "1.2"},
    {date: "03/05/15", rain: "2.3"},
    {date: "03/06/15", rain: "0.0"},
    {date: "03/07/15", rain: "4.2"},
    {date: "03/08/15", rain: "0.3"},
    {date: "03/09/15", rain: "0.0"}
]

我尝试按照简单教程会创建一个折线图,但是当我插入数据时,x轴或折线都不会显示.这与日期格式有关吗?

I've tried following a simple tutorial that creates a line graph, but when I plug in the data, neither the x axes or line will display. Does this have to do with date formatting?

我在 JS Bin 上举了一个例子.

我真的不明白问题出在哪里,请帮忙!

I really don't understand what the problem is, please help!

推荐答案

X轴应为 d3.time.scale ,由于您的date属性是字符串,因此您必须通过执行新的Date();来将其转换为正确的Date对象.

The X axis should be d3.time.scale and since your date property are strings you will have to convert it to proper Date objects by doing new Date();

这篇关于从数据对象数组创建折线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 05:07