c3.js how to set json datas in x/y Axis

独自空忆成欢 提交于 2020-01-07 03:16:14

问题


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

My Y Values should be ("Labels") and my X Values should be ("Datas"). So this is, how my Code looks like:

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

My "datas" (Array) are:

"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 labels :

 1234.433
 2234.431
 1231.546
 8965.354
 ....

How can I set now, my datas into the X-Axis and labels into Y?


回答1:


In order to create a date histogram, you have to define your x-axis as a timeseries.

The result looks like this:

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


来源:https://stackoverflow.com/questions/40918278/c3-js-how-to-set-json-datas-in-x-y-axis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!