* labelsize (number) : font size of the labels
* labelweight (string)(number) : font weight of the labels
* labelcolor (string) : font color of the labels
+ * showlabel (number) : only show label if the value >= 'showlabel'% of total
* legend (array) : legend
* legendpos (string) : position of the legend ('right' / 'bottom')
* legendkeyshape (string) : shape of the legend keys ('circle' / 'rect')
*/
function Piesectorchart(paper, width, height, cx, cy, r, values, opts) {
-
+
opts = opts || {};
var chartinst = this,
labelFont = opts.labelfont || "'Fontin Sans', Fontin-Sans, sans-serif",
labelSize = opts.labelsize || 18,
labelWeight = opts.labelweight || 'normal',
- labelColor = opts.labelcolor || '#FFFFFF';
+ labelColor = opts.labelcolor || '#FFFFFF',
+ showLabel = typeof(opts.showlabel) != 'undefined' ? opts.showlabel : 5; // default show label if value >= 5% of total
opts.barwidth = opts.barwidth || 80;
}
for (i = 0; i < len; i++) {
- // minimum degree of a pie shown
- if (defcut && values[i] * 360 / total <= 1.5) {
- cut = i;
- defcut = false;
- }
-
if (i > cut) {
defcut = false;
values[cut].value += values[i];
values[cut].others = true;
}
+
+ // minimum degree of a pie shown
+ if (defcut && values[i] * 360 / total <= 1.5) {
+ cut = i;
+ defcut = false;
+ }
}
len = Math.min(cut + 1, values.length);
a -= 360 * values[i] / total;
// show the label only if the values >= 5% of total
- if(labels && values[i] / total >= 0.05) {
- var text = labels[i];
+ if(labels && values[i] / total >= (showLabel / 100)) {
+ var text = labels[values[i].origin];
if(text.indexOf('#qty#') !== -1) {
- text = text.replace('#qty#', Math.round(values[i]));
+ text = text.replace('#qty#', Roo.util.Format.number(Math.round(values[i]), 0));
}
if(text.indexOf('#%#') !== -1) {
// draw legend
function legend(paper, cx, cy, r, values, opts, total, len)
{
- var legendPos = opts.legendpos || 'right',
+ var chartinst = this,
+ legendPos = opts.legendpos || 'right',
legendKeyShape = opts.legendkeyshape || 'circle',
legendKeySize = opts.legendkeysize || 12,
legendFont = opts.legendfont || "'Fontin Sans', Fontin-Sans, sans-serif",
var text = (values[i].others) ? opts.others : opts.legend[values[i].origin] || values[i];
if(text.indexOf('#qty#') !== -1) {
- text = text.replace('#qty#', Math.round(values[i]));
+ text = text.replace('#qty#', Roo.util.Format.number(Math.round(values[i]), 0));
}
if(text.indexOf('#%#') !== -1) {
var ty = iy - legendFontSize / 10;
- if(text.includes("\n")) {
+ if(text.indexOf("\n")> -1) {
var ty = iy - legendFontSize / 10 + legendFontSize / 2;
}