简体   繁体   中英

Google Pie Charts

http://code.google.com/intl/pl/apis/chart/interactive/docs/quick_start.html

Is possible add simply counter to legends? In this example:

Mushrooms (3)
 Onions (1)
Olives (1)
Zucchini (1)
Pepperoni (2)

Is possible to make? If yes, how?

You can do that easily by including the counter at the end of the legend string. Let's suppose your values come from an object with a structure such as:

var data = {
    'Mushrooms': 3,
    'Onions': 1,
    'Olives': 1,
    'Zucchini': 1,
    'Pepperoni': 2
}

What you can do is generate a rows array like:

var rows = [];
for (ingredient in data) {
    rows.push([
        ingredient + " (" + data[ingredient] + ")",
        data[ingredient
    ])
}

You can see it in action in this fiddle

The above is just a demo, when you pass your own objects you can pass any data you like.

Pass in the object(json for example)

function drawChart(json_obj){


var options = {'title':'How Much Pizza I Ate Last Night, Total: ' + json_obj.count,
                       'width':400,
                       'height':300};


}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM