Skip to content

Commit

Permalink
refs #3994 this fixes percentage values are always 0 in pie graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteur committed Oct 3, 2013
1 parent 11d2794 commit 896d110
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions plugins/CoreVisualizations/javascripts/jqplot.js
Expand Up @@ -117,13 +117,25 @@

_setTooltipPercentages: function () {
this.tooltip = {percentages: []};

for (var seriesIdx = 0; seriesIdx != this.data.length; ++seriesIdx) {
var series = this.data[seriesIdx];
var sum = series.reduce(function (previousValue, currentValue) { return previousValue + currentValue; }, 0);
var sum = series.reduce(function (previousValue, currentValue) {
if ($.isArray(currentValue) && currentValue[1]) {
return previousValue + currentValue[1];
}

return previousValue + currentValue;
}, 0);

var percentages = this.tooltip.percentages[seriesIdx] = [];
for (var valueIdx = 0; valueIdx != series.length; ++valueIdx) {
percentages[valueIdx] = sum > 0 ? Math.round(100 * series[valueIdx] / sum) : 0;
var value = series[valueIdx];
if ($.isArray(value) && value[1]) {
value = value[1];
}

percentages[valueIdx] = sum > 0 ? Math.round(100 * value / sum) : 0;
}
}
},
Expand Down

0 comments on commit 896d110

Please sign in to comment.