[42] | 1 | <?php // content="text/plain; charset=utf-8"
|
---|
| 2 | // Example for use of JpGraph,
|
---|
| 3 | // ljp, 01/03/01 20:32
|
---|
| 4 | require_once ('jpgraph/jpgraph.php');
|
---|
| 5 | require_once ('jpgraph/jpgraph_bar.php');
|
---|
| 6 |
|
---|
| 7 | // We need some data
|
---|
| 8 | $datay=array(-0.13,0.25,-0.21,0.35,0.31,0.04);
|
---|
| 9 | $datax=array("Jan","Feb","Mar","Apr","May","June");
|
---|
| 10 |
|
---|
| 11 | // Setup the graph.
|
---|
| 12 | $graph = new Graph(400,200);
|
---|
| 13 | $graph->img->SetMargin(60,20,30,50);
|
---|
| 14 | $graph->SetScale("textlin");
|
---|
| 15 | $graph->SetMarginColor("silver");
|
---|
| 16 | $graph->SetShadow();
|
---|
| 17 |
|
---|
| 18 | // Set up the title for the graph
|
---|
| 19 | $graph->title->Set("Example negative bars");
|
---|
| 20 | $graph->title->SetFont(FF_VERDANA,FS_NORMAL,16);
|
---|
| 21 | $graph->title->SetColor("darkred");
|
---|
| 22 |
|
---|
| 23 | // Setup font for axis
|
---|
| 24 | $graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,10);
|
---|
| 25 | $graph->yaxis->SetFont(FF_VERDANA,FS_NORMAL,10);
|
---|
| 26 |
|
---|
| 27 | // Show 0 label on Y-axis (default is not to show)
|
---|
| 28 | $graph->yscale->ticks->SupressZeroLabel(false);
|
---|
| 29 |
|
---|
| 30 | // Setup X-axis labels
|
---|
| 31 | $graph->xaxis->SetTickLabels($datax);
|
---|
| 32 | $graph->xaxis->SetLabelAngle(50);
|
---|
| 33 |
|
---|
| 34 | // Set X-axis at the minimum value of Y-axis (default will be at 0)
|
---|
| 35 | $graph->xaxis->SetPos("min"); // "min" will position the x-axis at the minimum value of the Y-axis
|
---|
| 36 |
|
---|
| 37 | // Create the bar pot
|
---|
| 38 | $bplot = new BarPlot($datay);
|
---|
| 39 | $bplot->SetWidth(0.6);
|
---|
| 40 |
|
---|
| 41 | // Setup color for gradient fill style
|
---|
| 42 | $bplot->SetFillGradient("navy","steelblue",GRAD_MIDVER);
|
---|
| 43 |
|
---|
| 44 | // Set color for the frame of each bar
|
---|
| 45 | $bplot->SetColor("navy");
|
---|
| 46 | $graph->Add($bplot);
|
---|
| 47 |
|
---|
| 48 | // Finally send the graph to the browser
|
---|
| 49 | $graph->Stroke();
|
---|
| 50 | ?>
|
---|