Adding value in Google Charts

513 views Asked by At

I'm trying to build a chart on some dynamic data. I found Google Chart api which looks easy to use however I'm having problem modifing my row values. For example in this code Mushroom initially has the value of 3 but later when I parse more data and I get more information about Mushroom I want to add it to my previouse value.

var data = new google.visualization.DataTable();
        data.addColumn('string', 'Topping');
        data.addColumn('number', 'Slices');
        data.addRows([
            ['Mushrooms', 3],
            ['Onions', 1],
            ['Mushrooms', 2]
        ]);

So I'm expecting to see Mushroom 5 in my chart it doest work

1

There are 1 answers

0
Henrik Aronsson On BEST ANSWER

data.setValue(0, 1, data.getValue(0, 1) + valueToAdd) would add valueToAdd to your already existing value.