简体   繁体   English

c3.js如何在x / y轴中设置json数据

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

I use c3 to create simple graphs. 我使用c3创建简单的图形。 I want to get datas from a Json file and fill it to create my Line-Graph. 我想从Json文件中获取数据并填充它以创建我的线图。

My Y Values should be ("Labels") and my X Values should be ("Datas"). 我的Y值应为(“标签”),而我的X值应为(“数据”)。 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? 现在如何设置数据到X轴和标签到Y轴?

In order to create a date histogram, you have to define your x-axis as a timeseries. 为了创建日期直方图,您必须将x轴定义为时间序列。

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"
            }
        }
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM