-
Notifications
You must be signed in to change notification settings - Fork 58
/
datescaleticksex01.php
68 lines (55 loc) · 1.8 KB
/
datescaleticksex01.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* JPGraph v3.6.15
*/
require_once __DIR__ . '/../../src/config.inc.php';
use Amenadiel\JpGraph\Graph;
use Amenadiel\JpGraph\Plot;
$INTERVAL = 5 * 60;
// First create some "dummy" data
$m = 5; // Number of data sets
$n = 4; // Number of bids to show
$startbid = 8000;
for ($i = 0; $i < $m; ++$i) {
$bids[$i] = [$startbid + rand(100, 500) * 10];
for ($j = 1; $j < $n; ++$j) {
$bids[$i][$j] = $bids[$i][$j - 1] + rand(20, 500) * 10;
}
}
$start = floor(time() / $INTERVAL) * $INTERVAL;
$times = [$start];
for ($i = 1; $i < $n; ++$i) {
// Create a timestamp for every 5 minutes
$times[$i] = $times[$i - 1] + $INTERVAL;
}
// Setup the bid graph
$__width = 600;
$__height = 250;
$graph = new Graph\Graph($__width, $__height);
$graph->SetMargin(80, 30, 50, 40);
$graph->SetMarginColor('white');
$graph->SetScale('dateint');
$graph->title->Set('Current Bids');
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 12);
$graph->subtitle->Set('(Updated every 5 minutes)');
$graph->subtitle->SetFont(FF_ARIAL, FS_ITALIC, 10);
// Enable antialias
$graph->img->SetAntiAliasing();
// Setup the y-axis to show currency values
$graph->yaxis->SetLabelFormatCallback('number_format');
$graph->yaxis->SetLabelFormat('$%s');
//Use hour:minute format for the labels
$graph->xaxis->scale->SetDateFormat('H:i');
// Force labels to only be displayed every 5 minutes
$graph->xaxis->scale->ticks->Set($INTERVAL);
// Adjust the start time for an "even" 5 minute, i.e. 5,10,15,20,25, ...
$graph->xaxis->scale->SetTimeAlign(MINADJ_5);
// Create the plots using the dummy data created at the beginning
$line = [];
for ($i = 0; $i < $m; ++$i) {
$line[$i] = new Plot\LinePlot($bids[$i], $times);
$line[$i]->mark->SetType(MARK_SQUARE);
}
$graph->Add($line);
// Send the graph back to the client
$graph->Stroke();