| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- echo $this->render("_nav", [
- 'boxId' => $boxId,
- 'config' => $config,
- 'themeJs' => $themeJs,
- 'themeConfig' => $themeConfig,
- 'columns' => $columns,
- ]);
- $jsonConfig = \yii\helpers\Json::encode($config);
- Yii::$app->view->registerJs(<<<JS
- var boxId = "$boxId";
- echartsList[boxId] = echarts.init(document.getElementById(boxId + '-echarts'), '$themeJs');
- echartsListConfig[boxId] = jQuery.parseJSON('$jsonConfig');
- // 动态加载数据
- $('#'+ boxId +' div span').click(function () {
- if (!$(this).data('type')) {
- return;
- }
-
- $(this).parent().find('span').removeClass('orange');
- $(this).addClass('orange');
- var data = {
- 'type': $(this).data('type'),
- 'echarts_type': 'pie',
- 'echarts_start': $(this).data('data-start'),
- 'echarts_end': $(this).data('data-end')
- }
-
- $(this).parent().parent().find('.echarts-input').each(function(index, item) {
- if ($(item).data('type') === 'dropDownList') {
- data[$(item).attr('name')] = $(item).val();
- }
-
- if ($(item).data('type') === 'radioList') {
- data[$(item).find('input:checked').attr('name')] = $(item).find('input:checked').val();
- }
- })
- var boxId = $(this).parent().parent().attr('id');
- var config = echartsListConfig[boxId];
-
- getPieData(boxId, config, data);
- });
-
- $('#'+ boxId +' .echarts-input').change(function() {
- var data = {};
- $(this).parent().parent().find('.echarts-input').each(function(index, item) {
- if ($(item).data('type') === 'dropDownList') {
- data[$(item).attr('name')] = $(item).val();
- }
-
- if ($(item).data('type') === 'radioList') {
- data[$(item).find('input:checked').attr('name')] = $(item).find('input:checked').val();
- }
- })
- var config = $(this).parent().parent().find('.orange:first');
- data['type'] = $(config).data('type');
- data['echarts_type'] = 'pie';
- data['echarts_start'] = $(config).attr('data-start');
- data['echarts_end'] = $(config).attr('data-end');
-
- getPieData(boxId, config, data);
- });
- // 首个触发点击
- $('#'+ boxId +' div span:first').trigger('click');
-
- function getPieData(boxId, config, data) {
- $.ajax({
- type:"get",
- url: config.server,
- dataType: "json",
- data: data,
- success: function(result){
- var data = result.data;
- if (parseInt(result.code) === 200) {
- echartsList[boxId].setOption({
- title : {
- text: '',
- subtext: '',
- x:'center'
- },
- legend: {
- orient: 'vertical',
- left: 'right',
- show: true,
- data: data.fieldsName
- },
- tooltip : {
- trigger: 'item',
- formatter: "{a} <br/>{b} : {c} ({d}%)"
- },
- calculable : true,
- series : data.seriesData
- }, true);
- } else {
- rfWarning(result.message);
- }
- }
- });
- }
- JS
- ) ?>
|