|
Legend Icon in Round Style for Donut Chart |
Posted by Adamraju on Sep-05-2022 16:14 |
|
Hi Team ,
We are creating Donut chart , by default Legend Icon is coming as Square , but we are looking for a circle icon
Can you please let us know , how can we do that.
Regards
Adamraju |
Re: Legend Icon in Round Style for Donut Chart |
Posted by Peter Kwan on Sep-06-2022 19:10 |
|
Hi Adamraju,
For pie/donut chart, the built-in legend entry always use a square box to show the color.
For your case, you may consider to generate the legend entry with your own code using CDML. I have attached two examples I have just written. One uses circles as icons, the other use donuts as icons.
The code I used (in Java) is as follows:
// As we display the percentage in the legend box, we need to compute it
double[] percentage = new ArrayMath(data).div(new ArrayMath(data).sum()/100).result();
// Create the legend entries using CDML
String legendEntries[] = new String[data.length];
for (int i = 0; i < data.length; ++i)
{
legendEntries[i] = String.format(
"<*block,valign=absmiddle*>%d. <*img=@circle,width=15,color=%x*> %s" +
"<*advanceTo=150*>%.2f%%<*/*>",
i + 1, Chart.DataColor + i, labels[i], percentage[i]);
}
// Add the legend entries to the chart, with one entry per line
c.addText(350, 175, "<*block,linespacing=1.2*>" + String.join("n", legendEntries), "Arial Bold", 12).setAlignment(Chart.Left);
The code above uses circle symbols. To change it to donut, just change the @circle to @PolyShape(0,500,500,500,NewShape,0,500,300,300).
The CDML method is very flexible. You can include other information in the legend box, and the texts in the legend box can use different fonts and colors. Follow the link below for the CDML syntax:
https://www.advsofteng.com/doc/cdjava.htm#cdml.htm
Best Regards
Peter Kwan
|
|