1 | <?php // content="text/plain; charset=utf-8" |
---|
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 | $graph = new Graph(400,200); |
---|
10 | $graph->SetScale('textlin'); |
---|
11 | $graph->SetY2Scale('lin'); |
---|
12 | $graph->SetShadow(); |
---|
13 | |
---|
14 | // Adjust the margin |
---|
15 | $graph->img->SetMargin(40,140,20,40); |
---|
16 | |
---|
17 | // Create the two linear plot |
---|
18 | $lineplot=new LinePlot($ydata); |
---|
19 | $lineplot2=new LinePlot($y2data); |
---|
20 | |
---|
21 | // Add the plot to the graph |
---|
22 | $graph->Add($lineplot); |
---|
23 | $graph->AddY2($lineplot2); |
---|
24 | $lineplot2->SetColor('orange'); |
---|
25 | $lineplot2->SetWeight(2); |
---|
26 | |
---|
27 | // Adjust the axis color |
---|
28 | $graph->y2axis->SetColor('orange'); |
---|
29 | $graph->yaxis->SetColor('blue'); |
---|
30 | |
---|
31 | $graph->title->Set('Example 6'); |
---|
32 | $graph->xaxis->title->Set('X-title'); |
---|
33 | $graph->yaxis->title->Set('Y-title'); |
---|
34 | |
---|
35 | $graph->title->SetFont(FF_FONT1,FS_BOLD); |
---|
36 | $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD); |
---|
37 | $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD); |
---|
38 | |
---|
39 | // Set the colors for the plots |
---|
40 | $lineplot->SetColor('blue'); |
---|
41 | $lineplot->SetWeight(2); |
---|
42 | $lineplot2->SetColor('orange'); |
---|
43 | $lineplot2->SetWeight(2); |
---|
44 | |
---|
45 | // Set the legends for the plots |
---|
46 | $lineplot->SetLegend('Plot 1'); |
---|
47 | $lineplot2->SetLegend('Plot 2'); |
---|
48 | |
---|
49 | // Adjust the legend position |
---|
50 | $graph->legend->Pos(0.05,0.5,'right','center'); |
---|
51 | |
---|
52 | // Display the graph |
---|
53 | $graph->Stroke(); |
---|
54 | ?> |
---|