LeMoussel
LeMoussel

Reputation: 5767

C3.js Legend Labels using JSON data

I have a donut graph, with a legend, that I made in C3.js. Actually, I do this to fill the chart.

var chartDonut = c3.generate({....});
chartDonut.load({
            columns: [
                ['Parfait', 190],
                ['Bien', 120],
                ['Trop court', 32],
                ['Trop long', 22],
            ],
            names: {
                'Parfait': 'Parfait (entre 50 \340 60 car.)',
                'Bien': 'Bien (entre 40 \340 49 ou  61 \340 69 car.)',
                'Trop court': 'Trop court (inf\351rieur \340 40 car.)',
                'Trop long': 'Trop long (sup\351rieur \340 79 car.)'            
            },
});

Everything works the way that I want it to, but I want to use JSON data. I do this

chartDonut.load({
            json: [
                    {"Parfait": 190},
                    {"Bien": 190},
                    {"Trop court": 190},
                    {"Trop long": 190}
            ],
            keys: {
                value: ['Parfait', 'Bien', 'Trop court', 'Trop long']
            },
});

but I have not found how to have the names properties in JSON format. Can someone help me? Thanks!

Upvotes: 0

Views: 1321

Answers (1)

ssc-hrep3
ssc-hrep3

Reputation: 16069

I'm not exactly sure what your problem is, but you can actually just add the names attribute to the object with the same content as above, similar as in your first solution. This will lead to the same output.

I created a jsFiddle, where I just copied your code (and switched from .load to the initial .generate) and added the names attribute to the the second object. See jsFiddle.

Upvotes: 2

Related Questions