treemapcolors.php
Back to Chart Graphics
addTitle("Energy Usage by Region", "Arial Bold Italic", 18);
# Set the plotarea at (10, 35) and of size 480 x 480 pixels
$c->setPlotArea(10, 35, 480, 480);
# Obtain the root of the tree map, which is the entire plot area
$root = $c->getRootNode();
# Add first level nodes to the root. We do not need to provide data as they will be computed as the
# sum of the second level nodes.
$root->setData(null, $allRegions);
# Add second level nodes to each of the first level node
$root->getNode(0)->setData($region0, $energy_types, $colors);
$root->getNode(1)->setData($region1, $energy_types, $colors);
$root->getNode(2)->setData($region2, $energy_types, $colors);
# Get the prototype (template) for the first level nodes.
$nodeConfig = $c->getLevelPrototype(1);
# Set the label format for the nodes to show the label with 8pt Arial Bold font in semi-transparent
# black color (0x77000000). Put the text at the top left corner of the cell.
$nodeConfig->setLabelFormat("{label}", "Arial Bold", 18, 0x77ffffff, TopLeft);
# Set the border color to white (ffffff). Use 2 pixel thick flat border style.
$nodeConfig->setColors(-1, 0xffffff, flatBorder(2));
# Get the prototype (template) for the second level nodes.
$nodeConfig2 = $c->getLevelPrototype(2);
# Set the label format for the nodes to show the label and value with 8pt Arial Bold font. Put the
# text at the center of the cell.
$nodeConfig2->setLabelFormat("{label}<*br*>{value}MW", "Arial Bold", 8, 0xffffff, Center);
# Set the border color to white (ffffff)
$nodeConfig2->setColors(-1, 0xffffff);
# Add a legend box at (500, 35) with 12pt Arial font and transparent background and border.
$b = $c->addLegend(500, 35, true, "Arial", 12);
$b->setBackground(Transparent, Transparent);
# Add the legend keys for the colors
for($i = 0; $i < count($energy_types); ++$i) {
$b->addKey($energy_types[$i], $colors[$i]);
}
# Output the chart
$viewer = new WebChartViewer("chart1");
$viewer->setChart($c, SVG);
# Include tool tip for the chart
$viewer->setImageMap($c->getHTMLImageMap("", "",
"title='<*cdml*>[{parent.label}] {label}: {value}MW'"));
?>
Tree Map Colors
Tree Map Colors
renderHTML(); ?>