line-bar.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. getLineBarData(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. getLineBarData(boxId, config, data);
  55. });
  56. // 首个触发点击
  57. $('#'+ boxId +' div span:first').trigger('click');
  58. function getLineBarData(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. echartsList[boxId].setOption({
  68. title : {
  69. text: '',
  70. subtext: ''
  71. },
  72. legend: {
  73. show: true,
  74. data: data.fieldsName
  75. },
  76. tooltip : {
  77. trigger: 'axis'
  78. },
  79. toolbox: {
  80. show : true,
  81. feature : {
  82. mark : {show: false},
  83. dataView : {show: false, readOnly: false},
  84. magicType : {show: true, type: ['line', 'bar']},
  85. restore : {show: false},
  86. saveAsImage : {show: false}
  87. }
  88. },
  89. calculable : true,
  90. xAxis : [
  91. {
  92. type : 'category',
  93. boundaryGap : false,
  94. data : data.xAxisData
  95. }
  96. ],
  97. yAxis : [
  98. {
  99. type : 'value',
  100. axisLabel : {
  101. formatter: '{value}'
  102. },
  103. }
  104. ],
  105. series : data.seriesData,
  106. }, true);
  107. } else {
  108. rfWarning(result.message);
  109. }
  110. }
  111. });
  112. }
  113. JS
  114. ) ?>
粤ICP备19079148号