line-graphic.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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-graphic',
  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. getLineGraphicData(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-graphic';
  52. data['echarts_start'] = $(config).attr('data-start');
  53. data['echarts_end'] = $(config).attr('data-end');
  54. getLineGraphicData(boxId, config, data);
  55. });
  56. // 首个触发点击
  57. $('#'+ boxId +' div span:first').trigger('click');
  58. function getLineGraphicData(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. color: ['#8EC9EB'],
  69. legend: {
  70. // data:['高度(km)与气温(°C)变化关系']
  71. },
  72. tooltip: {
  73. trigger: 'axis',
  74. },
  75. grid: {
  76. left: '3%',
  77. right: '4%',
  78. bottom: '3%',
  79. containLabel: true
  80. },
  81. xAxis: {
  82. type: 'value',
  83. splitLine: {
  84. show: false
  85. },
  86. axisLabel: {
  87. formatter: '{value}'
  88. }
  89. },
  90. yAxis: {
  91. type: 'category',
  92. axisLine: {onZero: false},
  93. axisLabel: {
  94. formatter: '{value}'
  95. },
  96. boundaryGap: true,
  97. data: data.fieldsName
  98. },
  99. graphic: [
  100. {
  101. type: 'image',
  102. id: 'logo',
  103. right: 20,
  104. top: 20,
  105. z: -10,
  106. bounding: 'raw',
  107. origin: [75, 75]
  108. }
  109. ],
  110. series: data.seriesData
  111. }, true);
  112. } else {
  113. rfWarning(result.message);
  114. }
  115. }
  116. });
  117. }
  118. JS
  119. ) ?>
粤ICP备19079148号