C3 - line chart time series error: x is not defined for id = "Dates"

C3 - line chart time series error: x is not defined for id = "Dates"

我正在尝试将时间序列作为 x 轴添加到 C3 中的两线图。不幸的是,我不知道该怎么做。它给出了错误 "x is not defined for id = "Dates"" 尽管我已经尝试尽可能地遵循 C3 的时间序列图表示例。

这是代码,有什么想法吗?

request.addEventListener('readystatechange', function () {
        if (this.readyState == 4) {
            var throughputReceived = JSON.parse(this.responseText).throughputReceived,
                throughputSent = JSON.parse(this.responseText).throughputSent,
                date = JSON.parse(this.responseText).date,
                chart,
                length = throughputReceived.length;

            for (var i = 0; i < length; i++) {
                throughputReceived[i] /= 1000000;
                throughputSent[i] /= 1000000;
                //                date[i] = moment(date[i]).format("YYYY MM DD hh ss");
            }

            throughputReceived.unshift('Throughput Received (Mbps)');
            throughputSent.unshift('Throughput Sent (Mbps)');
            date.unshift('Dates');

            chart = c3.generate({
                bindto: container,
                data: {
                    x: date,
                    columns: [date, throughputReceived, throughputSent]
                },
                axis: {
                    x: {
                        //                        label: 'Test No.'
                        type: 'timeseries',
                        tick: {
                            format: '%Y %m %d %h %s'
                        }
                    },
                    y: {
                        label: {
                            text: 'Throughput (Mbps)',
                            position: 'outer-top'
                        },
                        tick: {
                            format: d3.format('.2f')
                        }
                    }
                }
            });
        }
    });

你的定义 x-axis 错误。

您必须定义列的标题,而不是引用您的日期数组。

date.unshift('Awesome-Column');
...
data: {
        x: 'Awesome-Column',
        columns: [date, throughputReceived, throughputSent]
       },