-2

I am trying to create a C3 bar chat. Need to pass the JSON dynamically.

JSON: JSONdata

{ "applicationName": "app1", "frequency": 1 }, { "applicationName": "app2", "frequency": 54 }, { "applicationName": "app3", "frequency": 3 }  

I have the below code and it does not work. Tried using JSONdata.stringify() too.

var chart = c3.generate({

                        data: {
                            type: 'bar',
                            json: [
                                JSONdata                          
                            ],
                            keys: {
                                x: 'applicationName',
                               value: ['frequency']
                            }
                        },
                        axis: {
                            x: {
                                type: 'category'
                            }
                        },
                    bar: {
                        width: {
                            ratio: 0.5
                        }
                    }

                });
Avs_90
  • 49
  • 1
  • 6

1 Answers1

1

All that had to be done was:

var config = {};
config.data = {};
config.axis= {};
config.data.json = JSONdata;
config.data.type = 'bar';
config.data.keys=  {
                     x: 'applicationName',
                     value: ['frequency']
                    };
config.axis =  {
                    x: {
                        type: 'category'
                    }
                };
 config.bar = {
                    width: {
                        ratio: 0.9
                    }
                };

  var chart = c3.generate(config);
Avs_90
  • 49
  • 1
  • 6