xzonecolor.php
Back to Chart Graphics
setPlotArea(50, 10, 480, 180)->setGridColor(0xcccccc, 0xcccccc);
# Add a legend box (50, 10) (top of plot area) using horizontal layout. Use 8pt Arial font. Disable
# bounding box (set border to transparent).
$legendBox = $c->addLegend(50, 10, false, "", 8);
$legendBox->setBackground(Transparent);
# Add keys to the legend box to explain the color zones
$legendBox->addKey("Historical", 0x9999ff);
$legendBox->addKey("Forecast", 0xff9966);
# Add a title to the y axis.
$c->yAxis->setTitle("Energy Consumption");
# Set the labels on the x axis
$c->xAxis->setLabels2($labels);
# Set multi-style axis label formatting. Use Arial Bold font for yearly labels and display them as
# "yyyy". Use default font for monthly labels and display them as "mmm". Replace some labels with
# minor ticks to ensure the labels are at least 3 units apart.
$c->xAxis->setMultiFormat(StartOfYearFilter(), "<*font=Arial Bold*>{value|yyyy}",
StartOfMonthFilter(), "{value|mmm}", 3);
# Add a line layer to the chart
$layer = $c->addLineLayer2();
# Create the color to draw the data line. The line is blue (0x333399) to the left of x = 18, and
# become a red (0xd04040) dash line to the right of x = 18.
$lineColor = $layer->xZoneColor(18, 0x333399, $c->dashLineColor(0xd04040, DashLine));
# Add the data line
$layer->addDataSet($data, $lineColor, "Average");
# We are not showing the data set name in the legend box. The name is for showing in tool tips only.
$layer->setLegend(NoLegend);
# Create the color to draw the err zone. The color is semi-transparent blue (0x809999ff) to the left
# of x = 18, and become semi-transparent red (0x80ff9966) to the right of x = 18.
$errColor = $layer->xZoneColor(18, 0x809999ff, 0x80ff9966);
# Add the upper border of the err zone
$upperBorder = new ArrayMath($data);
$upperBorder->add($errData);
$layer->addDataSet($upperBorder->result(), $errColor, "Upper bound");
# Add the lower border of the err zone
$lowerBorder = new ArrayMath($data);
$lowerBorder->sub($errData);
$layer->addDataSet($lowerBorder->result(), $errColor, "Lower bound");
# Set the default line width to 2 pixels
$layer->setLineWidth(2);
# In this example, we are not showing the data set name in the legend box
$layer->setLegend(NoLegend);
# Color the region between the err zone lines
$c->addInterLineLayer($layer->getLine(1), $layer->getLine(2), $errColor);
# Output the chart
$viewer = new WebChartViewer("chart1");
$viewer->setChart($c, SVG);
# Include tool tip for the chart.
$viewer->setImageMap($c->getHTMLImageMap("", "",
"title='{dataSetName} on {xLabel|mmm yyyy}: {value} MJoule'"));
?>
X Zone Coloring
X Zone Coloring
renderHTML(); ?>