StackedBarGraph with legend
The code below is the source for this graph.
<?php
// StackedBarGraph with legend
require_once 'SVGGraph/autoloader.php';
$settings = [
'auto_fit' => true,
'back_colour' => '#eee',
'back_stroke_width' => 0,
'back_stroke_colour' => '#eee',
'stroke_colour' => '#000',
'axis_colour' => '#111',
'axis_overlap' => 2,
'grid_colour' => '#999',
'label_colour' => '#000',
'axis_font' => 'Arial',
'axis_font_size' => 12,
'pad_bottom' => 5,
'minimum_grid_spacing' => 20,
'show_subdivisions' => true,
'show_grid_subdivisions' => true,
'grid_subdivision_colour' => '#ccc',
'bar_label_colour' => '#fff',
'bar_label_font_size' => 11,
'legend_text_side' => 'left',
'legend_title' => 'Legend',
'legend_title_font_size' => 11,
'legend_reverse' => false,
'legend_position' => 'outer right 0 10',
'legend_back_colour' => '#eee',
'legend_shadow_opacity' => 0,
'legend_stroke_width' => 0,
'legend_draggable' => false,
'pad_right' => 100,
'show_bar_labels' => true,
'structured_data' => true,
'structure' => [
'key' => 0,
'value' => [1, 2],
'link' => [3, 4],
'tooltip' => [5, 6],
'label' => [7, 6],
'legend_text' => [0, null],
'colour' => [8, 9],
'axis_text' => 10,
],
];
$type = 'StackedBarGraph';
$width = 600;
$height = 200;
$colours = [ [ 'red', 'yellow' ], [ 'blue', 'white' ] ];
$values = [
[
"January", 10, 30, "svggraph-using.php", "svggraph-embed.php",
"Ten\nItems", "Bob", "**", "#f00", ["#f0f", "#303"], "J"
],
[
"February", 6, 20, "svggraph.php", "svggraph-settings.php",
"Six\nItems", "Anne", "*", "#f63", ["#63f", "#00c"], "F"
],
[
"March", 13, 18, "svggraph-bar.php", "svggraph-bar3d.php",
"Thirteen\nItems", "Sue", "***", "#f93", ["#93f", "#306"], "M"
],
[
"April", 16, 22, "svggraph-horizontal.php", "svggraph-line.php",
"Sixteen\nItems", "Frank", "***", "#fc0", "#c0f", "A"
],
[
"May", 18, 25, "svggraph-radar.php", "svggraph-scatter.php",
"Eighteen\nItems", "Alan", "****", "#9c0", "#63c", "M"
],
[
"June", 16, 28, "svggraph-pie.php", "svggraph-misc.php",
"Sixteen\nItems", "Vera", "***", "#3f0", ["#00f", "#003"], "J"
],
];
$graph = new Goat1000\SVGGraph\SVGGraph($width, $height, $settings);
$graph->colours($colours);
$graph->values($values);
$graph->render($type);
Please note: the source code above comes from a script used to generate one of the example graphs on the site. This is simply a wrapper page to apply highlighting and make the source code easier to read, so there is no content here to describe what the source code is doing.