C3.js how to set json data in x / y Axis

I use c3 to create simple graphs. I want to get data from a Json file and fill it in to create my Line-Graph.

My Y values โ€‹โ€‹should be ("Labels"), and my X values โ€‹โ€‹should be ("Dates"). So what my code looks like:

 var chart = c3.generate({
     bindto: '#chart',
     data: {
          xFormat: '%Y-%m-%dT%H:%M:%S',
          json: {
               times:datas,
               data: labels 
                 }
           }
      });

My "data" (array):

"2014-01-01T10:10:10"
"2014-02-01T10:10:10"
"2014-03-01T10:10:10"
"2014-04-01T10:10:10"
"2014-05-01T10:10:10"
...

And my shortcuts:

 1234.433
 2234.431
 1231.546
 8965.354
 ....

How can I set now, my data in X-Axis and labels in Y?

0
source share
1 answer

To create a date histogram, you must define your x axis as temporary.

The result is as follows:

var chart = c3.generate({
    data: {
        x: "time",
        json: {
            time: datas,
            data: labels
        }
    },
    axis:{
        x:{
            type: "timeseries",
            tick:{
                format:"%Y-%m-%dT%H:%M:%S"
            }
        }
    }
});
+1
source

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


All Articles