SVGGraph options: legend_entries_callback

« Return to previous page

Option name:
legend_entries_callback
Default value:
null
Added in version:
3.5
Data type:
callback [?]

The datatypes used in this documentation for specifying SVGGraph options are described below. All options can be a literal value of the data type described, a variable containing the data type, or an expression that will produce the data type when evaluated (and they must always be valid PHP expressions).

array
An array, the number and data types of its members will depend on the option for which is it used.
boolean
A boolean TRUE or FALSE value, or any values that convert easily such as 1, "1", 0 and "".
callback
A callable function, which can be either the name of a function or an anonymous function itself.
colour
Any of the colour values supported by SVG inside a single or double quoted string. These include three and six digit hex codes, RGB and RGBA colours, and colour names. SVG uses "none" for no colour, which generally leaves things transparent.
fill
A colour value or one of the gradients and patterns supported by SVGGraph. See the SVGGraph colours page for details.
integer
A negative or positive whole number or 0.
measurement
An integer or float value, or a string containing a number followed by one of these CSS units: px, in, cm, mm, pt, pc.
number
Any number supported by PHP, for example 1 or -3.2 or 1.63e5 or M_PI.
string
Single or double quoted strings. Remember to double-quote your strings if you are inserting a line break:
"Line 1\nLine 2".
Per-dataset:
no
Supported by:
ArrayGraph Bar3DGraph BarAndLineGraph BarGraph BoxAndWhiskerGraph BubbleGraph CandlestickGraph CylinderGraph Donut3DGraph DonutGraph EmptyGraph ExplodedDonut3DGraph ExplodedDonutGraph ExplodedPie3DGraph ExplodedPieGraph ExplodedSemiDonut3DGraph ExplodedSemiDonutGraph FloatingBarGraph GanttChart GroupedBar3DGraph GroupedBarGraph GroupedCylinderGraph Histogram HorizontalBar3DGraph HorizontalBarGraph HorizontalFloatingBarGraph HorizontalGroupedBar3DGraph HorizontalGroupedBarGraph HorizontalStackedBar3DGraph HorizontalStackedBarGraph LineGraph MultiLineGraph MultiRadarGraph MultiScatterGraph MultiSteppedLineGraph Pie3DGraph PieGraph PolarArea3DGraph PolarAreaGraph PopulationPyramid RadarGraph ScatterGraph SemiDonut3DGraph SemiDonutGraph StackedBar3DGraph StackedBarAndLineGraph StackedBarGraph StackedCylinderGraph StackedGroupedBar3DGraph StackedGroupedBarGraph StackedGroupedCylinderGraph StackedLineGraph SteppedLineGraph
Tags:
global legend callback

Allows modification of legend entries.

By implementing this callback you can change the order of the items in the legend, or change the text, or remove items.

The callback function is passed one argument, the array of LegendEntry objects to be displayed in the legend. The function must return an array of LegendEntry objects or an empty array to prevent the legend appearing at all.

The LegendEntry class has two properties that are useful in the callback function, text and item. The text member contains the text to be displayed and the item member refers to the data item that is related to the entry.

Example 1:

$settings = [
  'legend_entries_callback' => function($e) {
    $v = [];
    foreach($e as $i) {
      if(strpos($i->text, 'r')) {
        $v[] = $i;
      }
    }
    return $v; },
];

This example copies only those entries containing an 'r' in their text to the output array.

Example 2:

$settings = [
  'legend_entries_callback' => function($e) {
    $v = [];
    $num = 1;
    foreach($e as $i) {
      $i->text = sprintf('%d. %s', $num, $i->text);
      ++$num;
      $v[] = $i;
    }
    return $v; },
];

This example inserts a number in front of each of the entries in the legend.

See also:
legend_entries legend_unique_fields

« Back to top of page Main SVGGraph page »

This site uses cookies - details here.