This example is achieved by using zones and zone colors.
- The color of the bars is set to a y zone color, creating using Layer.yZoneColor. The y zone color is configured to be blue for y >= 0, and orange for y < 0.
- Similarly, the color of the bar labels are set a to another y zone color, which is slightly darker than the bar color.
- The two-color plot area background is achieved by using two zones, created by Axis.addZone.
[File: phpdemo/posnegbar.php".]
addTitle("Productivity Change - Year 2001", "arialbi.ttf");
#Set the plotarea at (50, 30) and of size 400 x 250 pixels
$c->setPlotArea(50, 30, 400, 250);
#Add a bar layer to the chart
$layer = $c->addBarLayer2();
#Add a data set to the bar using a y zone color. The color is configured to be
#orange (0xff6600) below zero, and blue (0x6666ff) above zero.
$layer->addDataSet($data, $layer->yZoneColor(0, 0xff6600, 0x6666ff));
#Add labels to the top of the bar using 8 pt Arial Bold font. The font color is
#configured to be red (0xcc3300) below zero, and blue (0x3333ff) above zero.
$layer->setAggregateLabelStyle("arialbd.ttf", 8, $layer->yZoneColor(0, 0xcc3300,
0x3333ff));
#Set the labels on the x axis and use Arial Bold as the label font
$labelsObj = $c->xAxis->setLabels($labels);
$labelsObj->setFontStyle("arialbd.ttf");
#Draw the y axis on the right of the plot area
$c->setYAxisOnRight(true);
#Use Arial Bold as the y axis label font
$c->yAxis->setLabelStyle("arialbd.ttf");
#Add a title to the y axis
$c->yAxis->setTitle("Percentage");
#Add a light blue (0xccccff) zone for positive part of the plot area
$c->yAxis->addZone(0, 9999, 0xccccff);
#Add a pink (0xffffcc) zone for negative part of the plot area
$c->yAxis->addZone(-9999, 0, 0xffcccc);
#output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?> |
© 2004 Advanced Software Engineering Limited. All rights reserved.