如何将数据传递到C3图形

问题描述:

这是我的JS代码:

var abc = JSON.stringify(dataObject);
var chart = c3.generate({
    bindto: '#container',
    data: {
       json: abc,
       keys: {
           x:'_id',
           value: ['a', 'b','c','d'],
       },
       axis: {
          x: {
              type: 'timeseries',
          }
      }

   }
});

上面的代码给出了错误:undefined is not a function.

The above code gives error:undefined is not a function.

但是,如果我直接直接提供相同的数据而不存储在变量中,则代码会起作用.
请让我知道错误是什么.

However if I directly give the same data directly without storing in a variable, the code works.
Please let me know what the mistake is.

根据此处的c3js文档: http://c3js.org/reference.html#data-json

According to c3js documentation here : http://c3js.org/reference.html#data-json

您不需要进行转换,因为您的密钥已经用双引号引起了,您将得到未定义的错误.您的数据已经是JSON,因此无需进行转换,除非语法错误,否则C3js会自动对其进行解析.

You don't need to convert, You are getting undefined error because your keys are already in double quotes. Your data is already JSON, therefore you don't need to convert it, C3js automatically parse it unless there is syntax error.

如果您的数据是有效的JSON/Javascript对象,则C3js将为您解析该数据.

If your data is valid JSON/Javascript object then C3js will parse it for you.

[{
    "_id": 1404412200000,
    "a": 6,
    "b": 10,
    "c": 6,
    "d": 20
}]

OR

[{
    _id: 1404412200000,
    a: 6,
    b: 10,
    c: 6,
    d: 20
}]

请注意,第一个是JSON,第二个是Javascript Object

Notice the difference first one is JSON and second one is Javascript Object