area-stack.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. echo $this->render("_nav", [
  3. 'boxId' => $boxId,
  4. 'config' => $config,
  5. 'themeJs' => $themeJs,
  6. 'themeConfig' => $themeConfig,
  7. 'columns' => $columns,
  8. ]);
  9. $jsonConfig = \yii\helpers\Json::encode($config);
  10. Yii::$app->view->registerJs(<<<JS
  11. var boxId = "$boxId";
  12. echartsList[boxId] = echarts.init(document.getElementById(boxId + '-echarts'), "$themeJs");
  13. echartsListConfig[boxId] = jQuery.parseJSON('$jsonConfig');
  14. // 动态加载数据
  15. $('#'+ boxId +' div span').click(function () {
  16. if (!$(this).data('type')) {
  17. return;
  18. }
  19. $(this).parent().find('span').removeClass('orange');
  20. $(this).addClass('orange');
  21. var data = {
  22. 'type': $(this).data('type'),
  23. 'echarts_type': 'line-bar',
  24. 'echarts_start': $(this).data('data-start'),
  25. 'echarts_end': $(this).data('data-end')
  26. }
  27. $(this).parent().parent().find('.echarts-input').each(function(index, item) {
  28. if ($(item).data('type') === 'dropDownList') {
  29. data[$(item).attr('name')] = $(item).val();
  30. }
  31. if ($(item).data('type') === 'radioList') {
  32. data[$(item).find('input:checked').attr('name')] = $(item).find('input:checked').val();
  33. }
  34. })
  35. var boxId = $(this).parent().parent().attr('id');
  36. var config = echartsListConfig[boxId];
  37. getAreaStackData(boxId, config, data);
  38. });
  39. $('#'+ boxId +' .echarts-input').change(function() {
  40. var data = {};
  41. $(this).parent().parent().find('.echarts-input').each(function(index, item) {
  42. if ($(item).data('type') === 'dropDownList') {
  43. data[$(item).attr('name')] = $(item).val();
  44. }
  45. if ($(item).data('type') === 'radioList') {
  46. data[$(item).find('input:checked').attr('name')] = $(item).find('input:checked').val();
  47. }
  48. })
  49. var config = $(this).parent().parent().find('.orange:first');
  50. data['type'] = $(config).data('type');
  51. data['echarts_type'] = 'line-bar';
  52. data['echarts_start'] = $(config).attr('data-start');
  53. data['echarts_end'] = $(config).attr('data-end');
  54. getAreaStackData(boxId, config, data);
  55. });
  56. // 首个触发点击
  57. $('#'+ boxId +' div span:first').trigger('click');
  58. function getAreaStackData(boxId, config, data) {
  59. $.ajax({
  60. type:"get",
  61. url: config.server,
  62. dataType: "json",
  63. data: data,
  64. success: function(result){
  65. var data = result.data;
  66. if (parseInt(result.code) === 200) {
  67. var seriesData = data.seriesData;
  68. for(let j = 0; j < seriesData.length; j++) {
  69. seriesData[j]['stack'] = '总数';
  70. seriesData[j]['areaStyle'] = [];
  71. seriesData[j]['areaStyle']['normal'] = {};
  72. }
  73. echartsList[boxId].setOption({
  74. title: {
  75. text: ''
  76. },
  77. tooltip : {
  78. trigger: 'axis',
  79. axisPointer: {
  80. type: 'cross',
  81. label: {
  82. backgroundColor: '#6a7985'
  83. }
  84. }
  85. },
  86. legend: {
  87. data: data.fieldsName
  88. },
  89. grid: {
  90. left: '3%',
  91. right: '4%',
  92. bottom: '3%',
  93. containLabel: true
  94. },
  95. xAxis : [
  96. {
  97. type : 'category',
  98. boundaryGap : false,
  99. data : data.xAxisData
  100. }
  101. ],
  102. yAxis : [
  103. {
  104. type : 'value'
  105. }
  106. ],
  107. series : data.seriesData,
  108. }, true);
  109. } else {
  110. rfWarning(result.message);
  111. }
  112. }
  113. });
  114. }
  115. JS
  116. ) ?>
粤ICP备19079148号