How to get data from c3.js

I am developing from c3.js using reusable charts in d3.js, but I can’t get data from an array of objects, I tried using this code format.

    var chart=c3.generate({
          data:{
              json:[
             {"key":[2000],"value":100},{"key":[2001],"value":200},{"key":[2003],"value":300},{"key":[2004],"value":400},{"key":[2005],"value":500},{"key":[2006],"value":600},{"key":[2007],"value":700}
                      ],
              keys:{x:'key[0]',
                    value:'value',
              }
   },
             axis: {
          x: {
            type: "category"
          }
        }

})
+4
source share
2 answers
chart.data('value')[0].values[0].value 

c3 documentation here

check out this fiddle

+4
source

I believe in this, for what you are going:

var chart = c3.generate({
        data:{
              json:[
             {"key":2000,"value":100},{"key":2001,"value":200},
             {"key":2003,"value":300},{"key":2004,"value":400},
             {"key":2005,"value":500},{"key":2006,"value":600},
             {"key":2007,"value":700}
              ],
              keys:{
                  x: "key",
                  value:['value']
              }
    },
    axis: {
          x: {
            type: "category"
          }
        }
});

I'm not sure why you will have a key for the data point, it is an array (maybe you want to change the keys and values?), But here is the basic key, a graph of value strings, which I think you are going to.

checkout out this fiddle adapted from Sikandar Tamboli's answer

0
source

All Articles