This sample shows a scatter plot (points plot) where the point colors are set using the number in a column, which selects from 1 of 3 colors. (2013-11-14)
Reference: Discussion forum thread
~~~~
:::php
<?php
// Scatterplot with colors example 2013-11-14
require_once 'phplot.php';
// Assume this is the result of a database query, perhaps something like
// this: SELECT xval, yval, mode FROM mytable ...
// Use 'mode' for the color, with values 1, 2, and 3.
// X Y Mode
$results = array(
array( 1, 10, 1),
array( 1, 80, 2),
array( 3, 30, 3),
array( 3, 60, 1),
array( 5, 50, 3),
array( 5, 40, 1),
array( 6, 50, 3),
array( 6, 40, 1),
array( 8, 30, 3),
array( 8, 60, 2),
array( 10, 10, 2),
array( 10, 80, 1),
);
// Make a PHPlot data array for a points plot, slotting the Y value in one
// of 3 columns according to the mode, in order to get 3 colors:
$data = array();
foreach ($results as $result_row) {
// Make a row with empty label, X, and Y in one of the 3 Y columns:
$row = array('', $result_row[0], '', '', '');
$row[$result_row[2] + 1] = $result_row[1];
$data[] = $row;
}
// Make a points plot using the above data:
$plot = new PHPlot(600, 400);
$plot->SetDataType('data-data');
$plot->SetDataValues($data);
$plot->SetPlotType('points');
// Set colors for 3 data sets:
$plot->SetDataColors(array('blue', 'red', 'green'));
// Use the same point shape for all data sets:
$plot->SetPointShapes('dot');
$plot->DrawGraph();
~~~~~