forked from onmotion/yii2-widget-apexcharts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApexchartsWidget.php
68 lines (53 loc) · 1.46 KB
/
ApexchartsWidget.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
/**
* @copyright Copyright (c) 2018
* @author Alexandr Kozhevnikov <[email protected]>
* @package yii2-widget-apexcharts
*/
namespace onmotion\apexcharts;
use yii\base\InvalidConfigException;
use yii\base\Widget;
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use yii\helpers\Json;
/**
*
* @property ActiveRecord|null $model
*/
class ApexchartsWidget extends Widget
{
public $id = 'apexcharts-widget';
public $timeout = 500;
public $chartOptions = [];
public $series = [];
public $type = 'line';
public $width = '100%';
public $height = 350;
public function init()
{
\Yii::setAlias('@apexchartsWidgetRoot', __DIR__);
parent::init();
}
public function getViewPath()
{
return \Yii::getAlias('@apexchartsWidgetRoot/views');
}
public function beforeRun()
{
return parent::beforeRun();
}
public function run()
{
parent::run();
ApexchartsWidgetAsset::register($this->getView());
$id = json_encode($this->getId());
$chartOptions = Json::encode($this->chartOptions);
$series = json_encode($this->series);
$type = json_encode($this->type);
$width = json_encode($this->width);
$height = json_encode((string)$this->height);
$timeout = $this->timeout;
echo $this->render('index', compact('id', 'timeout', 'chartOptions', 'series', 'type', 'width', 'height'));
}
}