This example extends the
Icon Pie Chart example to demonstrate using
CDML to include icons and multiple fonts in chart title, sector labels and to draw logo.
- The title containing multiple fonts and colors is written in CDML and added to the chart using BaseChart.addTitle.
- The logo designed using CDML is added to the chart as another title using BaseChart.addTitle2 with BottomRight alignment.
- The icons file names for sector labels are added to the chart as an extra field using PieChart.addExtraField.
- The sector label format is designed to include the icon using CDML and parameter substitution. It is then set into the pie chart using PieChart.setLabelFormat.
- The search path to load the icon images is configured to be the same as the script directory using BaseChart.setSearchPath. This is needed in IIS because the current directory in IIS is the directory of the IIS executable, not the script directory.
[File: phpdemo/iconpie2.php".]
setSearchPath(dirname(__FILE__));
#Set the center of the pie at (280, 140) and the radius to 100 pixels
$c->setPieSize(280, 140, 120);
#Add a title box with title written in CDML
$titleObj = $c->addTitle(
"<*block,valign=absmiddle*><*img=doc.png*><*font=timesbi.ttf,size=15*> ".
"Customer Survey : <*font=timesi.ttf*>Do you like our <*block,valign=top*>".
"<*font=mtcorsva.ttf,color=dd0000,size=17*>Hyper<*block*>".
"<*font=arial.ttf,size=8*> TM<*/*><*/*> molecules?<*/*>");
$titleObj->setBackground(0xccccff);
#Add a logo to the chart written in CDML as the bottom title aligned to the
#bottom right
$c->addTitle2(BottomRight,
"<*block,valign=absmiddle*><*img=molecule.png*> <*block*><*color=FF*>".
"<*font=mtcorsva.ttf,size=15*>Molecular Engineering\n".
"<*font=verdana.ttf,size=9*>Creating better molecules<*/*>");
#Set the pie data and the pie labels
$c->setData($data, $labels);
#Set 3D style
$c->set3D();
#Use the side label layout method
$c->setLabelLayout(SideLayout);
#Set the label background color to transparent
$labelStyleObj = $c->setLabelStyle();
$labelStyleObj->setBackground(Transparent);
#Set the join line color to black
$c->setJoinLine(0);
#Add icons to the chart as a custom field
$c->addExtraField($icons);
#Configure the sector labels using CDML to include the icon images
$c->setLabelFormat(
"<*block,valign=absmiddle*><*img={field0}*> {label} ({percent|0}%)");
#Explode the 3rd and 4th sectors as a group (index = 2 and 3)
$c->setExplodeGroup(2, 3);
#Set the start angle to 135 degrees may improve layout when there are many small
#sectors at the end of the data array (that is, data sorted in descending
#order). It is because this makes the small sectors position near the horizontal
#axis, where the text label has the least tendency to overlap. For data sorted
#in ascending order, a start angle of 45 degrees can be used instead.
$c->setStartAngle(135);
#output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?> |
© 2004 Advanced Software Engineering Limited. All rights reserved.