【问题标题】:javascript d3 render chartjavascript d3 渲染图表
【发布时间】:2020-07-21 14:31:51
【问题描述】:

我正在尝试学习一些用于前端 Web 开发的图表渲染技术。 There is a d3 tutorial 可以在网站上编辑 javascript 函数(非常适合学习目的),我正在尝试使用我自己的数据。在教程网站中,我正在尝试修改 rawgit

//Read the data
d3.csv("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/3_TwoNumOrdered_comma.csv",

使用我自己的 rawgit 数据集:

//Read the data
d3.csv("https://raw.githubusercontent.com/bbartling/Data/master/City%20Rec%20Center%202%20kW%202019.csv",

需要注意的是我的数据是每小时的,而教程数据是每天的。所以我需要用时间解析功能修改什么吗?

  // When reading the csv, I must format variables:
  function(d){
    return { date : d3.timeParse("%Y-%m-%d")(d.date), value : d.value }
  },

I am trying to follow this learn javascript site 谈论 timeParse 但没有任何运气...谁能给我提示?

还要提到我的数据集,时间戳/索引列是 Date 而不是 date 并且数据是 kW 而不是 value... 我是否也需要修改教程代码以适应这种情况?

【问题讨论】:

    标签: javascript d3.js web-frontend


    【解决方案1】:

    我想我真的想通了。至少我得到了要在教程网站上呈现的图表...将timeParse 函数更改为:

    //Read the data
    d3.csv("https://raw.githubusercontent.com/bbartling/Data/master/City%20Rec%20Center%202%20kW%202019.csv",
    
      // When reading the csv, I must format variables:
      function(d){
        return { date : d3.timeParse("%m/%d/%Y %H:%M")(d.Date), value : d.kW }
      },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-29
      • 2022-10-04
      • 1970-01-01
      • 2014-08-28
      相关资源
      最近更新 更多