AmChart百分比集群条形动态计算

时间:2016-03-11 01:06:57

标签: javascript percentage amcharts

我试图在每列中加上百分比计算。我怎么能这样做?

我现在有这个:

var legend = new AmCharts.AmLegend();
chart.addLegend(legend);

var qtd = 0;
var sum = 0;
for(i=0;i<datas.length;i++){
    sum[i] += Object.keys(datas[i]);
    qtd = (qtd < Object.keys(datas[i]).length - 1) ? Object.keys(datas[i]).length - 1 : qtd;
}
console.log(Object.keys(datas));
for(j=1;j<qtd+1;j++){
    datas[j].share = Math.round(datas[j].expenses / sum * 100);
    var graph = new AmCharts.AmGraph();
    graph.valueField = "expenses"+(j);
    graph.balloonText = "[[category]]: <b>[[value]]</b> ([[share]]%)";
    graph.labelText = "[[share]]%";
    graph.labelPosition = "inside";
    graph.type = "column";
    graph.fillAlphas = 0.8;
    chart.addGraph(graph);
}

https://jsfiddle.net/dayaners3/933t512e/

0 个答案:

没有答案