Repository navigation
Expand file tree
/
Copy pathdynamic.php
More file actions
67 lines (61 loc) · 1.68 KB
/
Copy pathdynamic.php
File metadata and controls
67 lines (61 loc) · 1.68 KB
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
<?php
/**
* Created by Hisune.
* User: hi@hisune.com
* Date: 2017/8/25
* Time: 09:56
*/
require('../vendor/autoload.php');
use Hisune\EchartsPHP\Config;
use Hisune\EchartsPHP\ECharts;
if(isset($_GET['ajax']) && $_GET['ajax'] == 'true'):
// Your data
echo json_encode(['num' => rand(0,100), 'data' => uniqid()]);
else:
// Your data
$data = [];
$xAxisData = [];
for($i = 0; $i < 50; $i++){
$data[] = rand(30,70);
$xAxisData[] = uniqid();
}
$chart = new ECharts();
$chart->xAxis = [
'type' => 'category',
'data' => $xAxisData,
];
$chart->yAxis[] = [
'type' => 'value',
];
$chart->series[] = [
'type' => 'line',
'data' => $data
];
Config::addExtraScript('jquery.min.js', '//cdn.bootcss.com/jquery/3.3.1');
echo $chart->render('test-id');
?>
<script>
setInterval(function(){
$.ajax({
data: {
'ajax': true
},
dataType: 'json',
success: function(json){
var echart = chart_<?=$chart->getJsVar()?>,
option = echart.getOption();
// shift a item then push a new
option.series[0].data.shift();
option.series[0].data.push(json.num);
option.xAxis[0].data.shift();
option.xAxis[0].data.push(json.data);
echart.setOption({
series: option.series,
xAxis: option.xAxis
});
}
});
}, 1000);
</script>
<?php
endif;