1 | <?php // content="text/plain; charset=utf-8"
|
---|
2 | require_once ('jpgraph/jpgraph.php');
|
---|
3 | require_once ('jpgraph/jpgraph_line.php');
|
---|
4 | require_once ('jpgraph/jpgraph_utils.inc.php');
|
---|
5 |
|
---|
6 | // Get a dataset stored in $xdata and $ydata
|
---|
7 | require_once ('dataset01.inc.php');
|
---|
8 |
|
---|
9 | $dateUtils = new DateScaleUtils();
|
---|
10 |
|
---|
11 | // Setup a basic graph
|
---|
12 | $width=500; $height=300;
|
---|
13 | $graph = new Graph($width, $height);
|
---|
14 |
|
---|
15 | // We set the x-scale min/max values to avoid empty space
|
---|
16 | // on the side of the plot
|
---|
17 | $graph->SetScale('intlin',0,0,min($xdata),max($xdata));
|
---|
18 | $graph->SetMargin(60,20,40,60);
|
---|
19 |
|
---|
20 | // Setup the titles
|
---|
21 | $graph->title->SetFont(FF_ARIAL,FS_BOLD,12);
|
---|
22 | $graph->title->Set('Development since 1984');
|
---|
23 | $graph->subtitle->SetFont(FF_ARIAL,FS_ITALIC,10);
|
---|
24 | $graph->subtitle->Set('(Example using DateScaleUtils class)');
|
---|
25 |
|
---|
26 | // Setup the labels to be correctly format on the X-axis
|
---|
27 | $graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
|
---|
28 | $graph->xaxis->SetLabelAngle(30);
|
---|
29 |
|
---|
30 | // The second paramter set to 'true' will make the library interpret the
|
---|
31 | // format string as a date format. We use a Month + Year format
|
---|
32 | $graph->xaxis->SetLabelFormatString('M, Y',true);
|
---|
33 |
|
---|
34 | // Get manual tick every second year
|
---|
35 | list($tickPos,$minTickPos) = $dateUtils->getTicks($xdata,DSUTILS_YEAR2);
|
---|
36 | $graph->xaxis->SetTickPositions($tickPos,$minTickPos);
|
---|
37 |
|
---|
38 | // First add an area plot
|
---|
39 | $lp1 = new LinePlot($ydata,$xdata);
|
---|
40 | $lp1->SetWeight(0);
|
---|
41 | $lp1->SetFillColor('orange@0.85');
|
---|
42 | $graph->Add($lp1);
|
---|
43 |
|
---|
44 | // And then add line. We use two plots in order to get a
|
---|
45 | // more distinct border on the graph
|
---|
46 | $lp2 = new LinePlot($ydata,$xdata);
|
---|
47 | $lp2->SetColor('orange');
|
---|
48 | $graph->Add($lp2);
|
---|
49 |
|
---|
50 | // And send back to the client
|
---|
51 | $graph->Stroke();
|
---|
52 |
|
---|
53 | ?>
|
---|