ChartDirector 7.0 (Perl Edition)

Heat Map Cell Symbols




This example demonstrates adding symbols and custom legend keys to the discrete heat map.

Source Code Listing

perldemo\heatmapcellsymbols.pl
#!/usr/bin/perl # The ChartDirector for Perl module is assumed to be in "../lib" use File::Basename; use lib (dirname($0)."/../lib") =~ /(.*)/; use perlchartdir; # The x-axis and y-axis labels my $xLabels = ["Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta", "Theta", "Iota", "Kappa" ]; my $yLabels = ["Ant", "Bear", "Cat", "Dog", "Elephant", "Fox", "Goat", "Horse", "Insect", "Jellyfish"]; # Random data for the 10 x 10 cells my $rand = new RanSeries(2); my $zData = $rand->getSeries(scalar(@$xLabels) * scalar(@$yLabels), 0, 10); # The coordinates for the first set of scatter symbols my $symbolX = [2.5, 6.5, 3.5, 8.5]; my $symbolY = [4.5, 7.5, 9.5, 8.5]; # The coordinates for the second set of scatter symbols my $symbol2X = [6.5, 3.5, 7.5, 1.5]; my $symbol2Y = [0.5, 7.5, 3.5, 2.5]; # Create an XYChart object of size 600 x 500 pixels. my $c = new XYChart(600, 500); # Set the plotarea at (80, 80) and of size 400 x 400 pixels. Set the background, border, and grid # lines to transparent. my $p = $c->setPlotArea(80, 80, 400, 400, -1, -1, $perlchartdir::Transparent, $perlchartdir::Transparent); # Add the first set of scatter symbols. Use grey (0x555555) cross shape symbols. $c->addScatterLayer($symbolX, $symbolY, "Disputed", perlchartdir::Cross2Shape(0.2), 15, 0x555555); # Add the first set of scatter symbols. Use yellow (0xffff66) star shape symbols. $c->addScatterLayer($symbol2X, $symbol2Y, "Audited", perlchartdir::StarShape(5), 19, 0xffff66); # Create a discrete heat map with 10 x 10 cells my $layer = $c->addDiscreteHeatMapLayer($zData, scalar(@$xLabels)); # Set the x-axis labels. Use 10pt Arial Bold font rotated by 90 degrees. Set axis stem to # transparent, so only the labels are visible. Set 0.5 offset to position the labels in between the # grid lines. Position the x-axis at the top of the chart. $c->xAxis()->setLabels($xLabels); $c->xAxis()->setLabelStyle("Arial Bold", 10, $perlchartdir::TextColor, 90); $c->xAxis()->setColors($perlchartdir::Transparent, $perlchartdir::TextColor); $c->xAxis()->setLabelOffset(0.5); $c->setXAxisOnTop(); # Set the y-axis labels. Use 10pt Arial Bold font. Set axis stem to transparent, so only the labels # are visible. Set 0.5 offset to position the labels in between the grid lines. Reverse the y-axis # so that the labels are flowing top-down instead of bottom-up. $c->yAxis()->setLabels($yLabels); $c->yAxis()->setLabelStyle("Arial Bold", 10); $c->yAxis()->setColors($perlchartdir::Transparent, $perlchartdir::TextColor); $c->yAxis()->setLabelOffset(0.5); $c->yAxis()->setReverse(); # Set the color stops and scale my $colorScale = [0, 0xff0000, 1, 0xff8800, 3, 0x4488cc, 7, 0x99ccff, 9, 0x00ff00, 10]; my $colorLabels = ["Poor", "Fair", "Good", "Very Good", "Excellent"]; $layer->colorAxis()->setColorScale($colorScale); # Position the legend box 20 pixels to the right of the plot area. Use 10pt Arial Bold font. Set the # key icon size to 15 x 15 pixels. Set vertical key spacing to 8 pixels. my $b = $c->addLegend($p->getRightX() + 20, $p->getTopY(), 1, "Arial Bold", 10); $b->setBackground($perlchartdir::Transparent, $perlchartdir::Transparent); $b->setKeySize(15, 15); $b->setKeySpacing(0, 8); # Add the color scale label to the legend box for(my $i = scalar(@$colorLabels) - 1; $i >= 0; --$i) { $b->addKey($colorLabels->[$i], int($colorScale->[$i * 2 + 1])); } # Output the chart $c->makeChart("heatmapcellsymbols.png");