1 | <?php // content="text/plain; charset=utf-8"
|
---|
2 |
|
---|
3 | require_once ('jpgraph/jpgraph.php');
|
---|
4 | require_once ('jpgraph/jpgraph_bar.php');
|
---|
5 |
|
---|
6 | // Some data
|
---|
7 | $datay1=array(140,110,50,60);
|
---|
8 | $datay2=array(35,90,190,190);
|
---|
9 | $datay3=array(20,60,70,140);
|
---|
10 |
|
---|
11 | // Create the basic graph
|
---|
12 | $graph = new Graph(450,250,'auto');
|
---|
13 | $graph->SetScale("textlin");
|
---|
14 | $graph->img->SetMargin(40,80,30,40);
|
---|
15 |
|
---|
16 | // Adjust the position of the legend box
|
---|
17 | $graph->legend->Pos(0.02,0.15);
|
---|
18 |
|
---|
19 | // Adjust the color for theshadow of the legend
|
---|
20 | $graph->legend->SetShadow('darkgray@0.5');
|
---|
21 | $graph->legend->SetFillColor('lightblue@0.3');
|
---|
22 |
|
---|
23 | // Get localised version of the month names
|
---|
24 | $graph->xaxis->SetTickLabels($gDateLocale->GetShortMonth());
|
---|
25 |
|
---|
26 | // Set a nice summer (in Stockholm) image
|
---|
27 | $graph->SetBackgroundImage('stship.jpg',BGIMG_COPY);
|
---|
28 |
|
---|
29 | // Set axis titles and fonts
|
---|
30 | $graph->xaxis->title->Set('Year 2002');
|
---|
31 | $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
|
---|
32 | $graph->xaxis->title->SetColor('white');
|
---|
33 |
|
---|
34 | $graph->xaxis->SetFont(FF_FONT1,FS_BOLD);
|
---|
35 | $graph->xaxis->SetColor('white');
|
---|
36 |
|
---|
37 | $graph->yaxis->SetFont(FF_FONT1,FS_BOLD);
|
---|
38 | $graph->yaxis->SetColor('white');
|
---|
39 |
|
---|
40 | //$graph->ygrid->Show(false);
|
---|
41 | $graph->ygrid->SetColor('white@0.5');
|
---|
42 |
|
---|
43 | // Setup graph title
|
---|
44 | $graph->title->Set('Using alpha blending with a background');
|
---|
45 | // Some extra margin (from the top)
|
---|
46 | $graph->title->SetMargin(3);
|
---|
47 | $graph->title->SetFont(FF_ARIAL,FS_NORMAL,12);
|
---|
48 |
|
---|
49 | // Create the three var series we will combine
|
---|
50 | $bplot1 = new BarPlot($datay1);
|
---|
51 | $bplot2 = new BarPlot($datay2);
|
---|
52 | $bplot3 = new BarPlot($datay3);
|
---|
53 |
|
---|
54 | // Setup the colors with 40% transparency (alpha channel)
|
---|
55 | $bplot1->SetFillColor('orange@0.4');
|
---|
56 | $bplot2->SetFillColor('brown@0.4');
|
---|
57 | $bplot3->SetFillColor('darkgreen@0.4');
|
---|
58 |
|
---|
59 | // Setup legends
|
---|
60 | $bplot1->SetLegend('Label 1');
|
---|
61 | $bplot2->SetLegend('Label 2');
|
---|
62 | $bplot3->SetLegend('Label 3');
|
---|
63 |
|
---|
64 | // Setup each bar with a shadow of 50% transparency
|
---|
65 | $bplot1->SetShadow('black@0.4');
|
---|
66 | $bplot2->SetShadow('black@0.4');
|
---|
67 | $bplot3->SetShadow('black@0.4');
|
---|
68 |
|
---|
69 | $gbarplot = new GroupBarPlot(array($bplot1,$bplot2,$bplot3));
|
---|
70 | $gbarplot->SetWidth(0.6);
|
---|
71 | $graph->Add($gbarplot);
|
---|
72 |
|
---|
73 | $graph->Stroke();
|
---|
74 | ?>
|
---|
75 |
|
---|