multicolorline.php
Back to Chart Graphics
setColor(TextColor, 0x333333);
# Add a title box using grey (0x555555) 20pt Arial font
$c->addTitle(" Multi-Color Line Chart", "Arial", 20, 0x555555);
# Set the plotarea at (70, 70) and of size 500 x 300 pixels, with transparent background and border
# and light grey (0xcccccc) horizontal grid lines
$c->setPlotArea(70, 70, 500, 300, Transparent, -1, Transparent, 0xcccccc);
# Add a legend box with horizontal layout above the plot area at (70, 35). Use 12pt Arial font,
# transparent background and border, and line style legend icon.
$b = $c->addLegend(70, 35, false, "Arial", 12);
$b->setBackground(Transparent, Transparent);
$b->setLineStyleKey();
# Set axis label font to 12pt Arial
$c->xAxis->setLabelStyle("Arial", 12);
$c->yAxis->setLabelStyle("Arial", 12);
# Set the x and y axis stems to transparent, and the x-axis tick color to grey (0xaaaaaa)
$c->xAxis->setColors(Transparent, TextColor, TextColor, 0xaaaaaa);
$c->yAxis->setColors(Transparent);
# Set the major/minor tick lengths for the x-axis to 10 and 0.
$c->xAxis->setTickLength(10, 0);
# For the automatic axis labels, set the minimum spacing to 80/40 pixels for the x/y axis.
$c->xAxis->setTickDensity(80);
$c->yAxis->setTickDensity(40);
# Add a title to the y axis using dark grey (0x555555) 14pt Arial font
$c->xAxis->setTitle("X-Axis Title Placeholder", "Arial", 14, 0x555555);
$c->yAxis->setTitle("Y-Axis Title Placeholder", "Arial", 14, 0x555555);
# In ChartDirector, each line layer can only have one line color, so we use 4 line layers to draw
# the 4 different colors of line segments.
# In general, the line segments for each color will not be continuous. In ChartDirector,
# non-continuous line segments can be achieved by inserting NoValue points. To allow for these extra
# points, we use a buffer twice the size of the original data arrays.
$lineX = array_fill(0, count($dataX) * 2, 0);
$lineY = array_fill(0, count($dataY) * 2, 0);
# Use a loop to create a line layer for each color
for($i = 0; $i < count($colors); ++$i) {
$n = 0;
for($j = 0; $j < count($dataX); ++$j) {
# We include data points of the target type in the line layer.
if (($j < count($pointType)) && ($pointType[$j] == $i)) {
$lineX[$n] = $dataX[$j];
$lineY[$n] = $dataY[$j];
$n = $n + 1;
} else if (($j > 0) && ($pointType[$j - 1] == $i)) {
# If the current point is not of the target, but the previous point is of the target
# type, we still need to include the current point in the line layer, as it takes two
# points to draw a line segment. We also need an extra NoValue point so that the current
# point will not join with the next point.
$lineX[$n] = $dataX[$j];
$lineY[$n] = $dataY[$j];
$n = $n + 1;
$lineX[$n] = $dataX[$j];
$lineY[$n] = NoValue;
$n = $n + 1;
}
}
# Draw the layer that contains all segments of the target color
$layer = $c->addLineLayer(array_slice($lineY, 0, $n - 0), $colors[$i], $pointTypeLabels[$i]);
$layer->setXData(array_slice($lineX, 0, $n - 0));
$layer->setLineWidth(2);
}
# Output the chart
$viewer = new WebChartViewer("chart1");
$viewer->setChart($c, SVG);
?>
Multi-Color Line Chart
Multi-Color Line Chart
renderHTML(); ?>