|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Jaxon\Jaxon; |
|
4
|
|
|
use Jaxon\Flot\FlotPlugin; |
|
5
|
|
|
|
|
6
|
|
|
class Flot extends \Jaxon\App\FuncComponent |
|
7
|
|
|
{ |
|
8
|
|
|
public function drawGraph() |
|
9
|
|
|
{ |
|
10
|
|
|
$flot = $this->response->plugin(FlotPlugin::class); |
|
11
|
|
|
// Create a new plot, to be displayed in the div with id "flot" |
|
12
|
|
|
$plot = $flot->plot('#flot')->width('450px')->height('300px'); |
|
|
|
|
|
|
13
|
|
|
// Set the ticks on X axis |
|
14
|
|
|
// $ticks = []; |
|
15
|
|
|
// for($i = 0; $i < 10; $i++) $ticks[] = [$i, 'Pt' . $i]; |
|
16
|
|
|
// $plot->xaxis()->points($ticks); |
|
17
|
|
|
$plot->xaxis()->expr(0, 16, 1, 'plots.xaxis.label'); |
|
18
|
|
|
|
|
19
|
|
|
// Add a first graph to the plot |
|
20
|
|
|
$graph = $plot->graph(['lines' => ['show' => true], 'label' => 'Sqrt']); |
|
21
|
|
|
$graph->series() |
|
22
|
|
|
->expr(0, 14, 0.5, 'plots.sqrt.value', 'plots.sqrt.label'); |
|
23
|
|
|
|
|
24
|
|
|
// Add a second graph to the plot |
|
25
|
|
|
$graph = $plot->graph([ |
|
26
|
|
|
'lines' => ['show' => true], |
|
27
|
|
|
'points' => ['show' => true], |
|
28
|
|
|
'label' => 'Graph 2', |
|
29
|
|
|
]); |
|
30
|
|
|
$graph->series()->points([ |
|
31
|
|
|
[0, 3, 'Pt 1'], |
|
32
|
|
|
[4, 8, 'Pt 2'], |
|
33
|
|
|
[8, 5, 'Pt 3'], |
|
34
|
|
|
[9, 13, 'Pt 4'], |
|
35
|
|
|
]); |
|
36
|
|
|
|
|
37
|
|
|
// Draw the graph |
|
38
|
|
|
$flot->draw($plot); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
// Register object |
|
43
|
|
|
$jaxon = jaxon(); |
|
44
|
|
|
|
|
45
|
|
|
$jaxonAppDir = dirname(__DIR__, 2) . '/public/app'; |
|
46
|
|
|
$jaxonAppURI = '/app'; |
|
47
|
|
|
|
|
48
|
|
|
$jaxon->setOption('js.app.export', true); |
|
49
|
|
|
$jaxon->setOption('js.app.dir', $jaxonAppDir); |
|
50
|
|
|
$jaxon->setOption('js.app.uri', $jaxonAppURI); |
|
51
|
|
|
$jaxon->setOption('js.app.minify', false); // Optionally, the file can be minified |
|
52
|
|
|
|
|
53
|
|
|
$jaxon->setOption('js.lib.uri', '/js'); |
|
54
|
|
|
$jaxon->register(Jaxon::CALLABLE_CLASS, Flot::class); |
|
55
|
|
|
|