root/trunk/flowmon-web/charts/stacked-bars.inc.php

Revision 4, 1.9 kB (checked in by ixs, 16 years ago)

Additional changes, nslookup support, added time selection to the chart itself...

Line 
1 <?php
2 #
3 # Copyright (C) 2008 Red Hat, Inc.
4 # Author: Andreas Thienemann <athienem@redhat.com>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU Library General Public License as published by
8 # the Free Software Foundation; version 2 only
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU Library General Public License for more details.
14 #
15 # You should have received a copy of the GNU Library General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #
19
20 require_once('phplot-5.0.5/phplot.php');
21
22 // accept data to plot through phplot
23 function draw_stackedbar($chart_title, $legend, $ytitle, $data) {
24
25
26     // Define general plot properties
27     $data_colors = array('SkyBlue', 'green', 'orange', 'blue', 'purple', 'red', 'violet', 'azure1', 'yellow', 'DarkGreen');
28
29     // Create the chart, write it to a newly created tmpfile.
30     $output = tempnam('tmp/', 'plot');
31
32     $plot = new PHPlot(900, 400);
33     $plot->SetIsInline(True);
34
35     //$plot->SetPrintImage(False);
36
37     $plot->SetImageBorderType('plain');
38     $plot->SetDataColors($data_colors);
39
40     $plot->SetPlotType('stackedbars');
41     $plot->SetDataType('text-data');
42     $plot->SetDataValues($data);
43
44     $plot->SetTitle($chart_title);
45     $plot->SetYTitle($ytitle);
46     $plot->SetLegend($legend);
47
48     $plot->SetXTickLabelPos('none');
49     $plot->SetXTickPos('none');
50
51     $plot->SetLegendPixels(760, 40);
52     $plot->SetMarginsPixels(100, 150, 50, 50);
53
54     $plot->SetNumberFormat(',', '.');
55     $plot->SetPrecisionY(0);
56     $plot->SetYLabelType('data');
57
58     $plot->SetOutputFile($output);
59     $plot->DrawGraph();
60
61     chmod($output, 0644);
62     $target dirname($output).'/'.basename($output).'.png';
63     if (rename($output, $target)) {
64         return 'tmp/'.basename($target);
65     } else {
66         return False;
67     }
68 }
69
70
Note: See TracBrowser for help on using the browser.