首页 > 解决方案 > (C3 js) 加载 CSV 文件并使用时间序列

问题描述

我正在尝试加载本地 csv 文件并使用时间序列。我有很多数据,所以我从 csv (url: 'data_testing.csv') 获取它,但我也想使用间隔为 12 小时的时间序列,总间隔为 5 天。我尝试了很多东西,但没有运气。似乎我要么必须使用来自同一脚本的数据(而不是加载 csv)才能使用时间序列。我可以加载 CSV,但是一旦我添加了时间序列,它就不再工作了。我也可以使用时间序列,但前提是数据来自列而不是来自文件加载。我需要同时处理时间序列 + CSV 文件中的数据。

C3 版本:0.6.8 - D3 版本:5.7.0 - 浏览器:Chrome - 操作系统:Mac OSX

var chart = c3.generate({
bindto: '#chart',
data: {
    // this only works if I don't use time series
    url: '../data_testing.csv',
    x: 'x',
    // this only works if I'm writing the data and not using local csv file
    xFormat: '%Y-%m-%d',
    columns: [
        ['x', '2016-8-10', '2016-8-10', '2016-8-10', '2016-8-10', '2016-8-10', '2016-8-10']
    ],
    type: 'line'

  },

axis: {
    x: {
        type: 'timeseries',
        localtime: false,
        tick: {
            culling: true,
            fit: true,
            culling: {
                max: window.innerWidth > 700 ? 8 : 5
            },
            format: '%Y-%m-%d' // %H:%M:%S
        }
    },
    y: {
        max: 55,
        min: 6
    }
}
  });

require(["d3", "c3"], function (d3, c3) {
      c3.generate({

   });
  });

标签: javascriptcsvd3.jsgraphc3.js

解决方案


推荐阅读