d3:来自数据的时间序列 [英] d3: timeseries from data

查看:112
本文介绍了d3:来自数据的时间序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过在函数中传递字典来创建时间序列.示例中的代码是这样的:

I want to create a timeseries by passing a dictionary in the function. The code from the examples is this:

d3.csv("data.csv", function(error, data) {
  data.forEach(function(d) {
    d.date = parseDate(d.date);
    d.close = +d.close;
  });

  x.domain(d3.extent(data, function(d) { return d.date; }));
  y.domain(d3.extent(data, function(d) { return d.close; }));
  //etc...

我想要做的是将其转换为一个函数,该函数接受带有日期并关闭行(数据)的对象,并由此生成图表,即

What I'm trying to do is to convert this into a function which takes an object with date and close rows (data) and produces the chart from this, i.e.

    function makeGraph(timeseriesdata){
        // create chart above from data
        // what format??
    }

推荐答案

d3.csv为您完成了大部分艰苦的工作.它需要一个csv并将其转换为对象数组,每个对象对应于csv的一行.

d3.csv does most of the hard work for you. It takes a csv and coverts it to an array of objects, each corresponding to a row of the csv.

https://github.com/mbostock/d3/wiki/CSV 具有一些例子.

调用d3.csv并使用parseDate清理数据后,可以将数据传递给makeGraph.

After calling d3.csv and cleaning up the data with parseDate, you can pass data to makeGraph.

d3.csv("data.csv", function(error, data) {
  data.forEach(function(d) {
   d.date = parseDate(d.date);
   d.close = +d.close;
  });
  makeGraph(data);
});

function makeGraph(timeseriesdata){

}

这篇关于d3:来自数据的时间序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆