C3 js line chart getting error for date

I am trying to use the ceries timeseries c3.js table (URL: http://c3js.org/samples/timeseries.html ). The only difference is that I use the CDN link for js files instead of downloading them. However, I keep getting the following error:

Chrome Error opening: x is not defined for id = "date".

Firefox Error: x is not defined for id = "date".

throw new Error ('x is not defined for id = "' + id + '".'); | ------------ +

Html file is below

<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>

<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.css"/>

<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.js"></script>

<script>
    var dates = ['20130101', '20130102', '20130103', '20130104', '20130105', '20130106'];
    var sample = [30, 200, 100, 400, 150, 250];

    var chart = c3.generate({
        bindto: '#chart',
        data: {
                x:'Dates',
                x_format:'%Y%m%d',
        columns: [
        //['Dates'].concat(dates),
        //['Sample'].concat(sample)
                ['date', '20130101', '20130102', '20130103', '20130104', '20130105', '20130106'],
                ['sample', 30, 200, 100, 400, 150, 250]
                ]
        },
        axis: {
                x: {
                    type : 'timeseries'
                }
        }
    });
</script>
</head>
<body>
    <div id="chart"></div>
</body>
</html>

, , . C3, .

+4
1

dates / "set", :

var dates = ['Dates', '20130101', '20130102', '20130103', '20130104', '20130105', '20130106'];

data object x . : dates date.

data: { x:'Dates', 

concat.

: http://jsfiddle.net/jrdsxvys/16/

+5

Source: https://habr.com/ru/post/1588903/


All Articles