问题
I want to write all of the total values in some where in graphics. My graphics may be column or stacked chart. How can I calculate all summ values in data and write?
"dataProvider": [ {
"country": "USA",
"visits": 2025
}, {
"country": "China",
"visits": 1882
}, {
"country": "Japan",
"visits": 1809
} ]
Or stacked data
"dataProvider": [{
"year": 2003,
"europe": 2.5,
"namerica": 2.5,
"asia": 2.1,
"lamerica": 0.3,
"meast": 0.2,
"africa": 0.1
}, {
"year": 2004,
"europe": 2.6,
"namerica": 2.7,
"asia": 2.2,
"lamerica": 0.3,
"meast": 0.3,
"africa": 0.1
}, {
"year": 2005,
"europe": 2.8,
"namerica": 2.9,
"asia": 2.4,
"lamerica": 0.3,
"meast": 0.3,
"africa": 0.1
}]
- Column chart
- Stacked chart
Or is it possible to write in legend like this: "General Sum: 1254"
回答1:
Set totalText in the value axis to generate a sum of the stack:
AmCharts.makeChart("chartdiv", {
// ...
valueAxes: [{
// ...
totalText: "Total: [[total]]"
}],
// ...
});
Demo
For single columns, try periodValueText in the legend.
AmCharts.makeChart("chartdiv", {
// ...
legend: {
// ...
periodValueText: "Selection total: [[value.sum]]"
}
// ...
});
Note this shows the sum of the columns in selected period/zoom for a particular graph.
Demo
来源:https://stackoverflow.com/questions/47721953/amchart-total-values-of-graphics