SetDataColors
Prev | PHPlot Function Reference | Next

## SetDataColors

SetDataColors — Set the colors for plotting data sets

## Synopsis

    $plot->SetDataColors($data_colors, [$border], [$default_alpha])

## Description

`SetDataColors` sets the colors used for plotting the data.

## Parameters

`$data_colors`

  An array of color values, one for each data set. Or, a single color value (not an array) to use for all data sets. For other possibilities, see Notes. See Section 3.5, “Colors” for more on color values.

`$border`

  Argument provided for backward compatibility. Use SetDataBorderColors instead.

`$default_alpha`

  A default alpha value to apply to all data colors which do not have an alpha value. This is generally useful only with Truecolor images. A value of zero means opaque, and 127 means fully transparent. See Section 4.2, “Truecolor Images” for more information.

## Notes

If an array is used for `$data_colors`, it must use zero based sequential integer indexes. This is what the PHP manual calls 'the usual integer indices (starting from zero, increasing by one)'.

Usually the `$data_colors` argument is an array of colors, one for each data set to be plotted. For example:

    $plot->SetDataColors(array('red', 'green', 'blue'));
    $plot->SetDataType('data-data');
    $plot->SetDataValues(array( array('', 1, 4, 10, 5),
                                array('', 2, 6, 20, 3)));

This will plot a red line from (1,4) to (2,6), a green line from (1,10) to (2,20), and a blue line from (1,5) to (2,3).

If `$data_colors` is not an array, but a single color value, then that color will be used for all data sets. However, the array(r,g,b) notation is not allowed in this case (because it looks like an array of 3 separate color values). You can get around this restriction if you want to specify a single color as an R, G, B array by wrapping the array in another array, for example: `array(array(102, 0, 192))`.

Two special uses of the `$data_colors` argument are available. If the argument is an empty string, or boolean False, the color map is reset to the defaults. This can be used to restore the default color map. If the argument is NULL or missing from the function call, the color map is reset to the defaults, but only if it has not already been set. This is used internal to PHPlot for one-time initialization.

If SetDataColors is never called, a default color map is used which contains 16 colors starting with SkyBlue, green, orange, and blue. For the full list, see Section 3.5.3, “Plotting Colors”. By default, all colors are opaque (alpha=0).

You can keep the default color map but set all colors in it to use a transparency (alpha) value like this:

    $plot->SetDataColors(NULL, NULL, 60);

This applies alpha=60 (meaning 60/127 transparency) to all the default data colors.

You can control how the data colors array is used with a data colors callback. See Section 4.4, “Custom Data Color Selection” for more information.

## History

The optional `$default_alpha` argument was added in PHPlot-5.1.1 when truecolor images were implemented.

Through PHPlot-5.0.7, the default color map contained these 8 colors: SkyBlue, green, orange, blue, orange, red, violet, and azure1. These were used if SetDataColors was never called. Unfortunately, orange is used twice, and azure1 is so close to the white background that it is invisible. Also, through PHPlot-5.0.7, if SetDataColors was called with an empty string argument, the color map was set to these 4 colors: blue red green orange. Starting with PHPlot-5.1.0, a new default color map with 16 colors was defined. Given an empty string (or False), SetDataColors now restores the default color map.

Prev | Up | Next
SetDataBorderColors | Home | SetDataType