echarts-block8.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. function loadBlock8() {
  2. const block8 = echarts.init(document.getElementById("block8"), "shine");
  3. var colorArray = [{
  4. top: '#ffa800', //黄
  5. bottom: 'rgba(11,42,84,.3)'
  6. }, {
  7. top: '#1ace4a', //绿
  8. bottom: 'rgba(11,42,84, 0.3)'
  9. },
  10. {
  11. top: '#4bf3ff', //蓝
  12. bottom: 'rgba(11,42,84,.3)'
  13. }, {
  14. top: '#4f9aff', //深蓝
  15. bottom: 'rgba(11,42,84,.3)'
  16. },
  17. {
  18. top: '#b250ff', //粉
  19. bottom: 'rgba(11,42,84,.3)'
  20. }
  21. ];
  22. const block8Opt = {
  23. tooltip: {
  24. show: true,
  25. formatter: "{b}:{c}"
  26. },
  27. grid: {
  28. left: '6%',
  29. top: '0',
  30. right: '4%',
  31. bottom: '8%',
  32. containLabel: true
  33. },
  34. xAxis: {
  35. type: 'value',
  36. show: false,
  37. position: 'top',
  38. axisTick: {
  39. show: false
  40. },
  41. axisLine: {
  42. show: false,
  43. lineStyle: {
  44. color: '#fff',
  45. }
  46. },
  47. splitLine: {
  48. show: false
  49. },
  50. },
  51. yAxis: [{
  52. type: 'category',
  53. axisTick: {
  54. show: false,
  55. alignWithLabel: false,
  56. length: 5,
  57. },
  58. "splitLine": { //网格线
  59. "show": false
  60. },
  61. inverse: 'true', //排序
  62. axisLine: {
  63. show: false,
  64. lineStyle: {
  65. color: '#fff',
  66. }
  67. },
  68. data: []
  69. }
  70. ],
  71. series: [{
  72. name: '重点单位场所',
  73. type: 'bar',
  74. label: {
  75. normal: {
  76. show: true,
  77. position: 'right',
  78. formatter: '{c}',
  79. textStyle: {
  80. color: 'white' //color of value
  81. }
  82. }
  83. },
  84. itemStyle: {
  85. normal: {
  86. show: true,
  87. color: function (params) {
  88. let num = colorArray.length;
  89. return {
  90. type: 'linear',
  91. colorStops: [{
  92. offset: 0,
  93. color: colorArray[params.dataIndex % num].bottom
  94. }, {
  95. offset: 1,
  96. color: colorArray[params.dataIndex % num].top
  97. }, {
  98. offset: 0,
  99. color: colorArray[params.dataIndex % num].bottom
  100. }, {
  101. offset: 1,
  102. color: colorArray[params.dataIndex % num].top
  103. }, {
  104. offset: 0,
  105. color: colorArray[params.dataIndex % num].bottom
  106. }, {
  107. offset: 1,
  108. color: colorArray[params.dataIndex % num].top
  109. }, {
  110. offset: 0,
  111. color: colorArray[params.dataIndex % num].bottom
  112. }, {
  113. offset: 1,
  114. color: colorArray[params.dataIndex % num].top
  115. }, {
  116. offset: 0,
  117. color: colorArray[params.dataIndex % num].bottom
  118. }, {
  119. offset: 1,
  120. color: colorArray[params.dataIndex % num].top
  121. }, {
  122. offset: 0,
  123. color: colorArray[params.dataIndex % num].bottom
  124. }, {
  125. offset: 1,
  126. color: colorArray[params.dataIndex % num].top
  127. }],
  128. //globalCoord: false
  129. }
  130. },
  131. barBorderRadius: 70,
  132. borderWidth: 0,
  133. borderColor: '#333',
  134. }
  135. },
  136. barGap: '0%',
  137. barCategoryGap: '50%',
  138. data: []
  139. }
  140. ]
  141. };
  142. block8.setOption(block8Opt);
  143. $.ajax({
  144. url: ajaxBaseUrl + "data/public-security.json",
  145. dataType: "json"
  146. }).done(function () {
  147. $("#block8").addClass("chart-done");
  148. }).done(function (data) {
  149. const yData = [];
  150. const seriesData = [];
  151. for (let i in data) {
  152. yData.push(data[i].name);
  153. seriesData.push(data[i].value);
  154. }
  155. block8.setOption({
  156. yAxis: {
  157. data: yData
  158. },
  159. series: [{
  160. data: seriesData
  161. }]
  162. });
  163. }).fail(function (jqXHR) {
  164. console.log("Ajax Fail: ", jqXHR.status, jqXHR.statusText);
  165. });
  166. }