This example shows the standard legend appearance, followed by the same plot with point shapes in the legend instead of color boxes. Using point shapes in the legend was added in PHPlot-5.4.0. This feature is useful if you need to be able to interpret the legend without color, for example with monochrome printing, or for accessibility reasons. See Section 3.7.2, “Legend” for more on the plot legend.
Example 5.35. Legend with Color Boxes or Point Shapes
First, here is the standard legend with color boxes.
<?php # PHPlot Example: Linepoints plot with legend using color boxes or shape markers require_once 'phplot.php'; # The variable $use_shapes can be set to TRUE in another # script which calls this script, to use shape markers # rather than color boxes in the legend. if (empty($use_shapes)) $use_shapes = FALSE; # Use data labels to display only the points we want, # but specify the same values for X to get the correct # spacing. $data = array( array('1990', 1990, 41308, 21015, 62634), array('1995', 1995, 44310, 13883, 61529), array('2000', 2000, 46772, 9000, 59421), array('2004', 2004, 46887, 7738, 57754), array('2006', 2006, 45441, 6888, 53179), array('2008', 2008, 42757, 5840, 49115), ); $legend_text = array('Morning Papers', 'Evening Papers', 'Sunday Papers'); $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetTitle("US Daily Newspaper Circulation\n" . '(Legend using ' . ($use_shapes ? 'shape markers' : 'color boxes') . ')'); $plot->SetPlotType('linepoints'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); $plot->SetPlotAreaWorld(1988, 0, 2010, 80000); $plot->SetYTickIncrement(10000); $plot->SetLegend($legend_text); $plot->SetXTickPos('none'); $plot->SetDrawXDataLabelLines(True); $plot->SetLegendUseShapes($use_shapes); // Use color boxes or shapes $plot->SetPointSizes(12); // Make points bigger for visibility $plot->DrawGraph();
Changing the call to SetLegendUseShapes results in a legend using point shapes instead of color boxes.
<?php # PHPlot Example: Linepoints plot with legend using shape markers # This sets a variable and calls the script directly above. $use_shapes = TRUE; require_once 'legendshape.php';