echarts-block9.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. function loadBlock9() {
  2. const block9 = echarts.init(document.getElementById("block9"), "macarons");
  3. let block9Opt = {
  4. color: ['#3398DB'],
  5. tooltip: {
  6. trigger: 'axis',
  7. axisPointer: {
  8. type: 'line',
  9. lineStyle: {
  10. opacity: 0
  11. }
  12. },
  13. formatter: function (params) {
  14. const marker = '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:#e6b600;"></span>';
  15. if (params[0].name !== '') {
  16. return params[0].name + "<br />" + marker + "数量:" + params[0].value + " 人";
  17. } else {
  18. return '';
  19. }
  20. }
  21. },
  22. legend: {
  23. show: false
  24. },
  25. grid: {
  26. left: '5%',
  27. right: '5%',
  28. bottom: '5%',
  29. top: '7%',
  30. height: '85%',
  31. containLabel: true,
  32. z: 22
  33. },
  34. xAxis: [{
  35. type: 'category',
  36. gridIndex: 0,
  37. data: [],
  38. axisTick: {
  39. alignWithLabel: true
  40. },
  41. axisLine: {
  42. lineStyle: {
  43. color: '#0c3b71'
  44. }
  45. },
  46. axisLabel: {
  47. show: true,
  48. color: 'rgb(170,170,170)',
  49. fontSize: 12
  50. }
  51. }],
  52. yAxis: [{
  53. type: 'value',
  54. gridIndex: 0,
  55. splitLine: {
  56. show: false
  57. },
  58. axisTick: {
  59. show: false
  60. },
  61. axisLine: {
  62. lineStyle: {
  63. color: '#0c3b71'
  64. }
  65. },
  66. axisLabel: {
  67. color: 'rgb(170,170,170)',
  68. formatter: '{value}'
  69. }
  70. },
  71. {
  72. type: 'value',
  73. gridIndex: 0,
  74. splitNumber: 12,
  75. splitLine: {
  76. show: false
  77. },
  78. axisLine: {
  79. show: false
  80. },
  81. axisTick: {
  82. show: false
  83. },
  84. axisLabel: {
  85. show: false
  86. },
  87. splitArea: {
  88. show: true,
  89. areaStyle: {
  90. color: ['rgba(250,250,250,0.0)', 'rgba(250,250,250,0.05)']
  91. }
  92. }
  93. }
  94. ],
  95. series: [{
  96. name: '实用人口',
  97. type: 'bar',
  98. barWidth: '30%',
  99. xAxisIndex: 0,
  100. yAxisIndex: 0,
  101. itemStyle: {
  102. normal: {
  103. barBorderRadius: 30,
  104. color: new echarts.graphic.LinearGradient(
  105. 0, 0, 0, 1, [{
  106. offset: 0,
  107. color: '#00feff'
  108. },
  109. {
  110. offset: 0.5,
  111. color: '#027eff'
  112. },
  113. {
  114. offset: 1,
  115. color: '#0286ff'
  116. }
  117. ]
  118. )
  119. }
  120. },
  121. data: [],
  122. zlevel: 11
  123. }]
  124. };
  125. block9.setOption(block9Opt);
  126. $.ajax({
  127. url: ajaxBaseUrl + "data/practical-person.json",
  128. dataType: "json"
  129. }).done(function () {
  130. $("#block9").addClass("chart-done");
  131. }).done(function (data) {
  132. var yData = [];
  133. var seriesData = [];
  134. for (var i = 0; i < data.length; i++) {
  135. yData.push(data[i].name);
  136. seriesData.push(data[i].value);
  137. }
  138. block9.setOption({
  139. xAxis: [{
  140. data: yData
  141. }],
  142. series: [{
  143. data: seriesData
  144. }]
  145. });
  146. }).fail(function (jqXHR) {
  147. console.log("Ajax Fail: ", jqXHR.status, jqXHR.statusText);
  148. });
  149. }