ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Inquiry About Legend Sorting in Pie Chart
Posted by Ji-hyeon Choi on Mar-11-2025 12:44
Attachments:
Hello,

I would like the pie chart's legend to be sorted as shown in the attached image on the right. Is there a way to achieve this?

We look forward to your response.
Best regards.
파이차트_현상.png

  Re: Inquiry About Legend Sorting in Pie Chart
Posted by Peter Kwan on Mar-11-2025 15:57
Hi Ji-hyeon,

The legend in the right pie chart starts from the red sector, and then flows anti-clockwise.

You can use PieChart.setStartAngle to configure ChartDirector to flow the sectors in the same way. See:

https://www.advsofteng.com/doc/cdjava.htm#anglepie.htm

For your case, please add the line:

// First sector (red) start at 90 degrees, and other sectors flow anti-clockwise
c.setStartAngle(90, false);

// Add border to the sectors. The border color is semi-transparent white (0x7fffffff)
c.setLineColor(0x7fffffff);

Best Regards
Peter Kwan

  Re: Inquiry About Legend Sorting in Pie Chart
Posted by Ji-hyeon Choi on Mar-11-2025 16:03
I'm sorry for the misunderstanding. What I meant was about the text in the legend.
Is it possible to align the values and text in the legend as shown on the right side of the image?

  Re: Inquiry About Legend Sorting in Pie Chart
Posted by Peter Kwan on Mar-11-2025 17:57
Hi Ji-hyeon,

You can use CDML formatting. See:

https://www.advsofteng.com/doc/cdjava.htm#legendpie2.htm

For your case, I thinking something like the followings may work:

b.setText("<*block,valign=top*><*block,width=150*>{label}<*/*>" +
     "<*block,width=60,halign=right*>{percent}%<*/*><*/*>");

The CDML syntax is explained below:

https://www.advsofteng.com/doc/cdjava.htm#cdml.htm

The available parameters that you can use (like {label}, {percent}, etc) are listed in the "Pie Chart" section in:

https://www.advsofteng.com/doc/cdjava.htm#paramsub.htm

Hope this can help.

Regards
Peter Kwan