1 | <?php |
---|
2 | require_once ('jpgraph/jpgraph.php'); |
---|
3 | require_once ('jpgraph/jpgraph_line.php'); |
---|
4 | |
---|
5 | $ydata = array(11,3,8,12,5,1,9,13,5,7); |
---|
6 | $y2data = array(354,200,265,99,111,91,198,225,293,251); |
---|
7 | |
---|
8 | // Create the graph and specify the scale for both Y-axis |
---|
9 | $width=550;$height=400; |
---|
10 | $graph = new Graph(550,400); |
---|
11 | $graph->SetScale('textlin'); |
---|
12 | $graph->SetY2Scale('lin'); |
---|
13 | $graph->SetShadow(); |
---|
14 | |
---|
15 | // Adjust the margin |
---|
16 | $graph->SetMargin(50,150,60,80); |
---|
17 | |
---|
18 | // Create the two linear plot |
---|
19 | $lineplot=new LinePlot($ydata); |
---|
20 | $lineplot2=new LinePlot($y2data); |
---|
21 | |
---|
22 | // Add the plot to the graph |
---|
23 | $graph->Add($lineplot); |
---|
24 | $graph->AddY2($lineplot2); |
---|
25 | $lineplot2->SetColor('orange'); |
---|
26 | $lineplot2->SetWeight(2); |
---|
27 | |
---|
28 | // Adjust the axis color |
---|
29 | $graph->y2axis->SetColor('darkred'); |
---|
30 | $graph->yaxis->SetColor('blue'); |
---|
31 | |
---|
32 | $graph->title->SetFont(FF_FONT0, FS_BOLD, 14); |
---|
33 | $graph->title->Set('Using JpGraph Library'); |
---|
34 | $graph->title->SetMargin(10); |
---|
35 | |
---|
36 | $graph->subtitle->SetFont(FF_FONT0, FS_BOLD, 10); |
---|
37 | $graph->subtitle->Set('(common objects)'); |
---|
38 | |
---|
39 | $graph->xaxis->title->SetFont(FF_FONT0, FS_BOLD, 10); |
---|
40 | $graph->xaxis->title->Set('X-title'); |
---|
41 | $graph->yaxis->title->SetFont(FF_FONT0, FS_BOLD, 10); |
---|
42 | $graph->yaxis->title->Set('Y-title'); |
---|
43 | |
---|
44 | // Set the colors for the plots |
---|
45 | $lineplot->SetColor('blue'); |
---|
46 | $lineplot->SetWeight(2); |
---|
47 | $lineplot2->SetColor('darkred'); |
---|
48 | $lineplot2->SetWeight(2); |
---|
49 | |
---|
50 | // Set the legends for the plots |
---|
51 | $lineplot->SetLegend('Plot 1'); |
---|
52 | $lineplot2->SetLegend('Plot 2'); |
---|
53 | |
---|
54 | // Adjust the legend position |
---|
55 | $graph->legend->SetPos(0.05,0.5,'right','center'); |
---|
56 | |
---|
57 | // Display the graph |
---|
58 | $graph->Stroke(); |
---|
59 | ?> |
---|