From dde085316c6f301ca26a9138779aad39c755c53d Mon Sep 17 00:00:00 2001 From: Rastislav Wartiak Date: Wed, 23 Dec 2020 18:18:26 +0100 Subject: [PATCH] Option to add customer JS code to customize the chart --- ApexchartsWidget.php | 4 +++- views/index.php | 20 +++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ApexchartsWidget.php b/ApexchartsWidget.php index e33d61b..0991bf0 100644 --- a/ApexchartsWidget.php +++ b/ApexchartsWidget.php @@ -28,6 +28,7 @@ class ApexchartsWidget extends Widget public $type = 'line'; public $width = '100%'; public $height = 350; + public $js = null; public function init() { @@ -60,8 +61,9 @@ public function run() $width = json_encode($this->width); $height = json_encode((string)$this->height); $timeout = $this->timeout; + $js = $this->js; - echo $this->render('index', compact('id', 'timeout', 'chartOptions', 'series', 'type', 'width', 'height')); + echo $this->render('index', compact('id', 'timeout', 'chartOptions', 'series', 'type', 'width', 'height', 'js')); } diff --git a/views/index.php b/views/index.php index e2db2ca..9ac8159 100644 --- a/views/index.php +++ b/views/index.php @@ -13,6 +13,7 @@ /** @var $width string */ /** @var $height string */ /** @var $timeout integer */ +/** @var $js \yii\web\JsExpression */ ?> @@ -26,17 +27,18 @@ setTimeout(function(e) { new Vue({ - el: '#' + $id, - data: function() { + el: '#' + $id, + data: function() { return { - chartOptions: $chartOptions, - series: $series, - type: $type, - width: $width, - height: $height + chartOptions: $chartOptions, + series: $series, + type: $type, + width: $width, + height: $height } - } -}); + } + }); + $js }, $timeout);