98 |
- |
1 |
<?php
|
|
|
2 |
# PHPlot / contrib / color_range : Example
|
|
|
3 |
# $Id: color_range.example.php 449 2009-12-09 03:45:45Z lbayuk $
|
|
|
4 |
# This is a bar chart with a color gradient for the bars in each group.
|
|
|
5 |
|
|
|
6 |
require_once 'phplot.php';
|
|
|
7 |
require_once 'color_range.php';
|
|
|
8 |
|
|
|
9 |
$bars_per_group = 10;
|
|
|
10 |
$x_values = 4;
|
|
|
11 |
|
|
|
12 |
mt_srand(1);
|
|
|
13 |
$data = array();
|
|
|
14 |
for ($i = 0; $i < $x_values; $i++) {
|
|
|
15 |
$row = array($i);
|
|
|
16 |
for ($j = 0; $j < $bars_per_group; $j++) $row[] = mt_rand(0, 100);
|
|
|
17 |
$data[] = $row;
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
$p = new PHPlot(800, 600);
|
|
|
21 |
$p->SetTitle('Example - Bar Chart with gradient colors');
|
|
|
22 |
$p->SetDataType('text-data');
|
|
|
23 |
$p->SetDataValues($data);
|
|
|
24 |
$p->SetPlotAreaWorld(0, 0, $x_values, 100);
|
|
|
25 |
|
|
|
26 |
# This isn't necessary, as we do know how many data sets (bars_per_group):
|
|
|
27 |
$n_data = count_data_sets($data, 'text-data');
|
|
|
28 |
# Make a gradient color map:
|
|
|
29 |
$colors = color_range($p->SetRGBColor('SkyBlue'),
|
|
|
30 |
$p->SetRGBColor('DarkGreen'), $n_data);
|
|
|
31 |
$p->SetDataColors($colors);
|
|
|
32 |
$p->SetXTickLabelPos('none');
|
|
|
33 |
$p->SetXTickPos('none');
|
|
|
34 |
$p->SetPlotType('bars');
|
|
|
35 |
$p->DrawGraph();
|