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

Message ListMessage List     Post MessagePost Message

  Pie chart labels overlapping
Posted by Leo on Mar-24-2012 00:24
Attachments:
Hello, Peter,

(1) how to fix the labels overlapping problems?
(2) how to extend the whole chart area to all edges?
(3) is the slice ordering according to data ordering?

Thanks.

perl code:


#!/usr/bin/perl
use perlchartdir;

# The data for the pie chart
my $data = [112324,40714,20651,6550,5937];
#my $data = [25, 18, 15, 12, 8, 30, 35];

# The labels for the pie chart
my $labels = ["Fixed Assets","Inventory","Intangibles","Cash & Equivalents","A/R"];
#my $labels = ["Labor", "A/R", "Taxes", "Legal", "Insurance", "Facilities",
"Production"];

# Create a PieChart object of size 360 x 300 pixels
#my $c = new PieChart(300, 300);
my $c = new PieChart(380, 380);

# Set the center of the pie at (180, 140) and the radius to 100 pixels
$c->setPieSize(180, 150, 90);
#$c->setPieSize(140, 140, 80);
#$c->setPieSize(-1, -1, 80);

# Set the pie data and the pie labels
$c->setLabelStyle("arialbd.ttf", 12);
$c->setData($data, $labels);

# Output the chart
$c->makeChart("apie.21855.png")
badpie.png

  Re: Pie chart labels overlapping
Posted by Peter Kwan on Mar-27-2012 00:55
Attachments:
Hi Leo,

(1) To avoid labels overlapping, you may use the SideLayout method. See the sample code "Side Label Layout"  (you may look up "Side Label Layout" in the ChartDirector documentation index).

I have modified your code to use SideLayout for your reference:

use perlchartdir;

# The data for the pie chart
my $data = [112324,40714,20651,6550,5937];
#my $data = [25, 18, 15, 12, 8, 30, 35];

# The labels for the pie chart
my $labels = ["Fixed Assets","Inventory","Intangibles","Cash & Equivalents","A/R"];

my $c = new PieChart(500, 220);

# Set the center of the pie at (180, 140) and the radius to 100 pixels
$c->setPieSize(250, 110, 90);
$c->setLabelLayout($perlchartdir::SideLayout, 30);

# Set the pie data and the pie labels
$c->setLabelStyle("arialbd.ttf", 12)->setMaxWidth(120);
$c->setData($data, $labels);

# Output the chart
$c->makeChart("apie.21855.png")

(2) Because text flows horizontally, so it is normal that a pie chart should have a larger width and smaller height. In the above code, I choose 500 x 220 as the size. You may put the pie at the center (250, 110). I have configured the labels to be 30 pixels from the pie (see the setLabelLayout code), and the radius of the pie is 90 pixels. This leaves 130 pixels for the labels. I have set the label box maximum width to 120 pixels (leaving 10 pixels as margin).

(3) Yes. The slices are ordered based on your data order.

Hope this can help.

Regards
Peter Kwan
simplepie.png

  Re: Pie chart labels overlapping
Posted by Leo on Mar-27-2012 10:54
Excellent, Thanks A Million..