0

我正在尝试用两列为给定数据绘制时间序列图,第一列有时间戳,第二列是当时的相应电压值。通过 C3.js url 方法访问数据文件并指定日期时间的解析格式。输出没有出现。我不知道,但是,我在这里尝试的方式是否正确?请帮助我。

这是我的 C3 脚本:

        var chart=c3.generate({
               data: {
                   url: '/data/data.csv'
                   x: 'timestamp'
                   xFormat: '%m/%d/%Y %H:%M:%S %p' 
//                 My date format in .csv file is: 9/30/2015  6:38:00 PM
                   columns: [
                        ['timestamp', ... ],
                        ['voltage', ... ]
                    ]
               },
               axis: {
                    x: {
                        type: 'timeseries',
                        tick: {
                            format: function(x) {
                                retun x.getDate();
                            }
                        }
                    }
               }
            });

4

1 回答 1

1

After some experimentation I modified your code, added the commas (,) needed to separate the parameters, and I got your code snippet working. Here is the revised code:

var chart=c3.generate({
   data: {
       url: 'data/data.csv',
       x: 'timestamp',
       xFormat: '%m/%d/%Y %H:%M:%S %p',
        //~ My date format in .csv file is: 3/2/2016 6:44:00 PM
       columns: [
            ['timestamp'],
            ['voltage']
        ]
    },
    axis: {
        x: {
                type: 'timeseries',
                tick: {format: function (x) { return x.getHours(); }}
            }
        }
});

In the 'tick' parameter I believe you need to utilize JavaScript datetime methods such as 'getHours()' because you are trying to format the dates in that line, not get new dates. In my case the the output is in 0 to 24 hour increments.

Also, my data.csv file looks like this:

 timestamp,voltage
 3/2/2016 6:44:00 PM,30.893
 3/2/2016 4:57:00 PM,75.964
 3/2/2016 3:43:00 PM,96.37
 3/2/2016 2:38:00 PM,99.157
 3/2/2016 1:29:00 PM,85.335
 3/2/2016 11:16:00 AM,31.445
于 2016-03-03T02:31:59.693 回答