c3 chart in angularJS

1k views Asked by At

I have my JSON data from URL using angular js and assigned to $scope.values. Now I want to feed this value to chart using the c3 chart.

I have a dummy chart using below code.

jsonData.forEach(function(e) {
    sites.push(e.name);
    })    
var chart = c3.generate({
    bindto: '#chart1',
    data: {
        json: [ data ],

How can I pass the json values to the chart?

1

There are 1 answers

3
Akoya On

The data.json is expecting following format:

data: {
  json: {
    data1: [1,3,3,7],
    otherdata: [9,0,0,0]
  }
} 

You can either pass multiple columns to data.json or you can add each colmn kinda manually.

var myjson = { data1:[1,3,3,7], data2:[9,0,0,0] }

data: {
      json: myjson
} 

var mydata = [1,3,3,7]

data: {
  json: {
    data1: mydata
  }
}