pie.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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': 'pie',
  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. getPieData(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'] = 'pie';
  52. data['echarts_start'] = $(config).attr('data-start');
  53. data['echarts_end'] = $(config).attr('data-end');
  54. getPieData(boxId, config, data);
  55. });
  56. // 首个触发点击
  57. $('#'+ boxId +' div span:first').trigger('click');
  58. function getPieData(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. x:'center'
  72. },
  73. legend: {
  74. orient: 'vertical',
  75. left: 'right',
  76. show: true,
  77. data: data.fieldsName
  78. },
  79. tooltip : {
  80. trigger: 'item',
  81. formatter: "{a} <br/>{b} : {c} ({d}%)"
  82. },
  83. calculable : true,
  84. series : data.seriesData
  85. }, true);
  86. } else {
  87. rfWarning(result.message);
  88. }
  89. }
  90. });
  91. }
  92. JS
  93. ) ?>
粤ICP备19079148号