Create a multi-point gradient color.
In this method, the color points are defined as an array of positions and colors along a gradient line segment. During definition, the gradient line segment is always assumed to be horizontal and 256 pixels in length. When actually creating the gradient color, the direction and length of the gradient line can be controlled using the
angle and
scale parameters.
The array of positions and their colors along the gradient line is of the following format:
position0, color0, position1, color1, position2, color2, .... positionN, colorN
where positionX is the pixel position along the gradient line, and colorX is the color at that position. During definition, the gradient line it is always assumed to be 256 pixels in length, so position0 is always 0, and the last position is always 256.
For example, the array (in hex):
000000, FF0000, 000080, FFFF00, 000100, 00FF00
means pixel 0 (000000) is red (FF0000), pixel 128 (000080) is yellow (FFFF00), and pixel 256 (000100) is green (00FF00).
One common use of multi-point gradient colors is to define colors that have metallic look and feel. ChartDirector comes from several pre-defined gradient color arrays as follows.
Name | Value (in hex numbers) |
goldGradient | 000000, FFE743, 000060, FFFFE0, 0000B0, FFF0B0, 000100, FFE743 |
silverGradient | 000000, C8C8C8, 000060, F8F8F8, 0000B0, E0E0E0, 000100, C8C8C8 |
redMetalGradient | 000000, E09898, 000060, FFF0F0, 0000B0, F0D8D8, 000100, E09898 |
greenMetalGradient | 000000, 98E098, 000060, F0FFF0, 0000B0, D8F0D8, 000100, 98E098 |
blueMetalGradient | 000000, 9898E0, 000060, F0F0FF, 0000B0, D8D8F0, 000100, 9898E0 |
Return a 32-bit integer acting as a handle to the gradient color. The handle can be used in any ChartDirector API that expects a color as an argument.
© 2004 Advanced Software Engineering Limited. All rights reserved.
bj = $c->setPlotArea(100, 25, 450, 150);
$plotAreaObj->setGridColor(0xc0c0c0, 0xc0c0c0);
#Add a legend box (92, 0) (top of plot area) using horizontal layout. Use 8 pts
#Arial font. Disable bounding box (set border to transparent).
$legendObj = $c->addLegend(92, 0, false, "", 8);
$legendObj->setBackground(Transparent);
#Add a title to the y axis. Draw the title upright (font angle = 0)
$titleObj = $c->yAxis->setTitle("Average\nUtilization\n(MBytes)");
$titleObj->setFontAngle(0);
#Use manually scaling of y axis from 0 to 100, with ticks every 10 units
$c->yAxis->setLinearScale(0, 100, 10);
#Set the labels on the x axis
$c->xAxis->setLabels2($labels);
#Set the title on the x axis
$c->xAxis->setTitle("Jun - 2001");
#Add x axis (vertical) zones to indicate Saturdays and Sundays
for($i = 0; $i < 29; $i += 7) {
$c->xAxis->addZone($i, $i + 2, 0xc0c0c0);
}
#Add a line layer to the chart
$layer = $c->addLineLayer();
#Set the default line width to 2 pixels
$layer->setLineWidth(2);
#Add the three data sets to the line layer
$layer->addDataSet($data0, 0xcf4040, "Server #1");
$layer->addDataSet($data1, 0x40cf40, "Server #2");
$layer->addDataSet($data2, 0x4040cf, "Server #3");
#Layout the chart to fix the y axis scaling. We can then use getXCoor and
#getYCoor to determine the position of custom objects.
$c->layout();
#Add the "week n" custom text boxes at the top of the plot area.
for($i = 0; $i < 4; ++$i) {
#Add the "week n" text box using 8 pt Arial font with top center alignment.
$textbox = $c->addText($layer->getXCoor($i * 7 + 2), 25, "Week $i",
"arialbd.ttf", 8, 0x0, TopCenter);
#Set the box width to cover five days
$textbox->setSize($layer->getXCoor($i * 7 + 7) - $layer->getXCoor($i * 7 + 2
) + 1, 0);
#Set box background to pale yellow 0xffff80, with a 1 pixel 3D border
$textbox->setBackground(0xffff80, Transparent, 1);
}
#output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?>
© 2004 Advanced Software Engineering Limited. All rights reserved.
bels. In this example, the labels must be Jan - Dec.
$labels = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
"Sept", "Oct", "Nov", "Dec");
$c->xAxis->setLabels($labels);
#Set the x-axis width to 2 pixels
$c->xAxis->setWidth(2);
#Set the y axis title
$c->yAxis->setTitle("USD (K)");
#Set the y-axis width to 2 pixels
$c->yAxis->setWidth(2);
#Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?>© 2004 Advanced Software Engineering Limited. All rights reserved.
ved using © 2004 Advanced Software Engineering Limited. All rights reserved.
01', '959', '1018', '1102');