SVGGraph 2.22


Version 2.22 is another small SVGGraph update, this time improving the way that the legend works. The bulk of the legend code has been moved out of the main class into a new SVGGraphLegend.php file which is only loaded if you are using a legend. Here's an example bar and line graph:

BarAndLineGraph with legend

This graph is using legend_entries to set an entry for each dataset, but it is also using the new legend_text option for structured data, adding an entry to the legend for the red marker in the “Jul 2016” position. The data and relevant options are shown in the code snippets below.

$settings = array(
  'structure' => array(
    'key' => 0,
    'value' => array(1, 2),
    'colour' => array(null, 3),
    'marker_stroke_colour' => array(null, 4),
    'legend_text' => array(null, 5),
    'axis_text' => 'axis',
  'legend_entries' => array(
  'legend_position' => 'bottom right -5 -5',

I've only included the legend-related options in this code extract, there are quite a few more options used to achieve the graph at the top of the page.

$values = array(
  array(0, 1500, 90, 'axis' => 'Jan 2016'),
  array(1, 1550, 76, 'axis' => 'Feb 2016'),
  array(2, 1530, 65, 'axis' => 'Mar 2016'),
  array(3, 1580, 57, 'axis' => 'Apr 2016'),
  array(4, 1300, 59, 'axis' => 'May 2016'),
  array(5, 1220, 55, 'axis' => 'Jun 2016'),
  array(6, 2500, 98, '#f00', '#fc3', 'New market!', 'axis' => 'Jul 2016'),
  array(7, 2300, 80, 'axis' => 'Aug 2016'),
  array(8, 2350, 97, 'axis' => 'Sep 2016'),
  array(9, 2280, 85, 'axis' => 'Oct 2016'),

You can continue to use legend_entries by itself, or you can use the structured legend_text by itself instead. There is another new option in this version, show_legend, which you can use to turn the legend on or off. It defaults to TRUE for backwards-compatibility – if you are upgrading, don't forget to install the new svggraph.ini file.

Version 2.22 also adds support for multiple lines of text in the legend entries and title.

An unrelated addition to this version is support for shapes and labels using coordinates from the second Y-axis. The dotted red line on the example graph is drawn from grid positions 60 to 90 on the second axis, using this config:

  $settings['shape'] = array('line',
    'x1' => 'gl', 'x2' => 'gr',
    'y1' => 'g60y1', 'y2' => 'g90y1',
    'stroke' => '#f00', 'stroke-width' => 2, 'stroke-dasharray' => '5'

The “g60y1” means at grid position 60 on Y axis 1 (the right axis is number 1, the left axis is 0).

There is one obscure bug fixed in this version - character entities would be measured as a single character, but displayed as the entity code. Which means µ would count as a single character when SVGGraph was trying to figure out how much space the string takes up, but then it would go ahead and display “µ” on the graph instead of “µ”. It should display the correct character now.

The new version is available from the downloads page, or from GitHub, or using Composer.

« Previous: JPEG Saver 4.17 Next: TrayBlank 1.7 »