18 function __construct( $filename = "graph.png" )
20 $this->output_file = 'templates_c/' . $filename;
23 public function SetData( $data_in, $type, $data_type, $shading = 5 )
25 $this->data = $data_in;
27 $this->data_type = $data_type;
28 $this->shadding = $shading;
31 public function SetGraphSize( $width, $height )
33 $this->width = $width;
34 $this->height = $height;
37 public function SetTitle( $title )
40 $this->title = $title;
42 die( "Please provide a non empty title for the graph" );
45 public function SetColors( $colors )
47 if( is_array( $colors ) )
48 $this->colors = $colors;
50 die( "Please provide a array in BGraph->SetColors()" );
53 public function Get_Image_file()
55 return $this->output_file;
58 public function Render()
61 $this->plot = new PHPlot( $this->width, $this->height );
63 // Render to file instead of screen
64 $this->plot->SetOutputFile( $this->output_file );
65 $this->plot->SetFileFormat("png");
66 $this->plot->SetIsInline( true );
69 $this->plot->SetImageBorderType('plain');
71 // Data, type and data type
72 $this->plot->SetPlotType( $this->type );
73 $this->plot->SetDataType( $this->data_type );
74 $this->plot->SetDataValues( $this->data );
77 $this->plot->SetDataColors( $this->colors );
80 $this->plot->SetShading( $this->shading );
83 $this->plot->SetImageBorderType( 'none' );
85 // Plot area (calculated regarding the width and height of the graph)
86 if( $this->type == 'pie' )
87 $this->plot->SetPlotAreaPixels( 10, 10, ($this->width / 2), $this->height-10 );
89 // Legend position (calculated regarding the width and height of the graph)
90 $this->plot->SetLegendPixels( ($this->width / 2) + 10, 25 );
92 // Labels scale position
93 if( $this->type == 'pie' )
94 $this->plot->SetLabelScalePosition( 0.2 );
97 $this->plot->SetTitle( $this->title );
100 if( $this->type != 'bars' ) {
102 foreach( $this->data as $key => $legend ) {
103 $this->plot->SetLegend( implode(': ',$legend) );
107 # Turn off X tick labels and ticks because they don't apply here:
108 $this->plot->SetXTickLabelPos('none');
109 $this->plot->SetXTickPos('none');
110 $this->plot->SetPlotAreaWorld(NULL, 0, NULL, NULL);
113 $this->plot->DrawGraph();
114 } // end function Render()
115 } // end BGraph classe