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

Message ListMessage List     Post MessagePost Message

  How to overlap a pie chart with donut chart(s)?
Posted by Vincent Chang on Apr-20-2018 01:31
Hi,

How are you doing? I am trying to overlap a pie chart at the center with donut chart(s) around it.

I am able to draw pie chart and donut chart, but having problem to merge them together. Do you have any example codes in PHP that I can take a look as example?

Thanks

Vincent

  Re: How to overlap a pie chart with donut chart(s)?
Posted by Peter Kwan on Apr-20-2018 14:53
Hi Vincent,

Yes, there is an example "Concentric Donut Chart" that comes with the ChartDirector distribution.

http://www.advsofteng.com/doc/cdphp.htm#concentric.htm

The example above uses two donut charts, but you can easily change the chart at the center to a pie chart by changing:

$c2->setDonutSize(110, 110, 100, 50);

to

$c2->setPieSize(110, 110, 100);

Hope this can help.

Regards
Peter Kwan

  Re: How to overlap a pie chart with donut chart(s)?
Posted by Vincent Chang on Apr-21-2018 06:21
Hi Peter,

Thank you for the answer. I have one more question for you, is there a way to draw partial donut like 1/8 or 1/4 of donut instead of full donut?

Thanks

Vincent

  Re: How to overlap a pie chart with donut chart(s)?
Posted by Peter Kwan on Apr-21-2018 14:57
Hi Vincent,

The easiest method is to add a transparent sector. The sector fill and edge colors can be configued using Sector.setColor and the sector label color (if you chart has sector labels) using Sector.setLabelStyle. You can set all these colors to transparent. See:

http://www.advsofteng.com/doc/cdphp.htm#Sector.setColor.htm
http://www.advsofteng.com/doc/cdphp.htm#Sector.setLabelStyle.htm

Hope this can help.

Regards
Peter Kwan

  Re: How to overlap a pie chart with donut chart(s)?
Posted by Vincent Chang on Apr-25-2018 09:22
Hi Peter,

Thank you for the info. There is another question coming up from a colleague ->
       If we have 5 items with value 90, 5, 2, 2, and 1 for example. Is there a way we can draw a donut chart that is evenly divided into 5 sectors (or at least increase the sector size of small values)  and still showing correct values - 90, 5, 2, 2, and 1? We are looking for a way to present those small sectors with readable sectors.

Thanks

  Re: How to overlap a pie chart with donut chart(s)?
Posted by Peter Kwan on Apr-25-2018 11:44
Hi Vincent,

There are several methods. Currently, the pie chart takes two arrays for the data values and the labels. You can modify the data values to increase the smaller sector size, and include the real values in the labels.

For example, suppose your sectors are (100, 1, 1) and your labels are ("AAA", "BBB", "CCC"). You can change the sectors to (100, 10, 10) and the labels to ("AAA:100", "BBB:1", "CCC:1"). Then in the code, you can configure the visible labels to just include the labels but not the data value:

$c->setLabelFormat("{label}");

Another method is to create 3 arrays - one for the size, the other for the data values for display, and the third of the labels. Then in your pie chart, you use:

#use the size to plot the chart
$c->setData($size, $labels);

#add the real values as an extra field
$c->addExtraField($realValues);

#configure the visible label to show the label and the extra field
$c->setLabelFormat("{label}: {field0}");

Hope this can help.

Regards
Peter Kwan

  Re: How to overlap a pie chart with donut chart(s)?
Posted by Vincent Chang on Apr-27-2018 08:26
Hi Peter,

Thank you so much, that works like a charm.

Vincent