How to pass data to c3 graph

梦想的初衷 提交于 2020-01-06 08:45:17

问题


Here is my JS code:

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',
          }
      }

   }
});

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.


回答1:


i got the Answer , it works fine with me . Remove JSON.stringify(dataObject).

it will already Stringify by the c3.js it self




回答2:


Remove JSON.stringify(dataObject).

It will already Stringify by the c3.js itself




回答3:


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

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.

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
}]

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




回答4:


I stopped in the same error. I think stringify adds characters c3js no interpret



来源:https://stackoverflow.com/questions/26582181/how-to-pass-data-to-c3-graph

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