wordcloud.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. var geoCoordMap;
  13. echartsList[boxId] = echarts.init(document.getElementById(boxId + '-echarts'), '$themeJs');
  14. echartsListConfig[boxId] = jQuery.parseJSON('$jsonConfig');
  15. // 动态加载数据
  16. $('#'+ boxId +' div span').click(function () {
  17. if (!$(this).data('type')) {
  18. return;
  19. }
  20. $(this).parent().find('span').removeClass('orange');
  21. $(this).addClass('orange');
  22. var data = {
  23. 'type': $(this).data('type'),
  24. 'echarts_type': 'wordcloud',
  25. 'echarts_start': $(this).data('data-start'),
  26. 'echarts_end': $(this).data('data-end')
  27. }
  28. $(this).parent().parent().find('.echarts-input').each(function(index, item) {
  29. if ($(item).data('type') === 'dropDownList') {
  30. data[$(item).attr('name')] = $(item).val();
  31. }
  32. if ($(item).data('type') === 'radioList') {
  33. data[$(item).find('input:checked').attr('name')] = $(item).find('input:checked').val();
  34. }
  35. })
  36. var boxId = $(this).parent().parent().attr('id');
  37. var config = echartsListConfig[boxId];
  38. getWordcloudData(boxId, config, data);
  39. });
  40. $('#'+ boxId +' .echarts-input').change(function() {
  41. var data = {};
  42. $(this).parent().parent().find('.echarts-input').each(function(index, item) {
  43. if ($(item).data('type') === 'dropDownList') {
  44. data[$(item).attr('name')] = $(item).val();
  45. }
  46. if ($(item).data('type') === 'radioList') {
  47. data[$(item).find('input:checked').attr('name')] = $(item).find('input:checked').val();
  48. }
  49. })
  50. var config = $(this).parent().parent().find('.orange:first');
  51. data['type'] = $(config).data('type');
  52. data['echarts_type'] = 'wordcloud';
  53. data['echarts_start'] = $(config).attr('data-start');
  54. data['echarts_end'] = $(config).attr('data-end');
  55. getWordcloudData(boxId, config, data);
  56. });
  57. // 首个触发点击
  58. $('#'+ boxId +' div span:first').trigger('click');
  59. function getWordcloudData(boxId, config, data) {
  60. $.ajax({
  61. type:"get",
  62. url: config.server,
  63. dataType: "json",
  64. data: data,
  65. success: function(result){
  66. var data = result.data;
  67. if (parseInt(result.code) === 200) {
  68. geoCoordMap = data.geoCoordMapData;
  69. echartsList[boxId].setOption({
  70. tooltip: {},
  71. series: [ {
  72. type: 'wordCloud',
  73. gridSize: 2,
  74. sizeRange: [12, 50],
  75. rotationRange: [-90, 90],
  76. shape: 'pentagon',
  77. width: '100%',
  78. height: '100%',
  79. drawOutOfBound: true,
  80. textStyle: {
  81. normal: {
  82. color: function () {
  83. return 'rgb(' + [
  84. Math.round(Math.random() * 255),
  85. Math.round(Math.random() * 255),
  86. Math.round(Math.random() * 255)
  87. ].join(',') + ')';
  88. },
  89. },
  90. emphasis: {
  91. shadowBlur: 10,
  92. shadowColor: '#333'
  93. }
  94. },
  95. data: data.seriesData
  96. } ]
  97. }, true);
  98. } else {
  99. rfWarning(result.message);
  100. }
  101. }
  102. });
  103. }
  104. JS
  105. ) ?>
粤ICP备19079148号