echarts-block3.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. function loadBlock3() {
  2. const block3 = echarts.init(document.getElementById("block3"), "shine");
  3. const block3Opt = {
  4. tooltip: {
  5. trigger: "axis",
  6. // axisPointer: {
  7. // type: "cross"
  8. // },
  9. formatter: function (params) {
  10. const param = params[0];
  11. const marker = '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:#e6b600;"></span>';
  12. // const suffix = '<span style="margin-left:5px;font-size:12px;">亿元</span>';
  13. return param.name + "<br />" +
  14. // marker + "排名:" + (param.dataIndex + 1) + "<br />" +
  15. marker + "人员数量:" + param.value + " 人";
  16. }
  17. },
  18. grid: {
  19. width: '80%',
  20. height: '80%',
  21. left: '10%',
  22. top: '5%',
  23. },
  24. xAxis: {
  25. data: [],
  26. axisTick: {
  27. show: false
  28. },
  29. axisLine: {
  30. lineStyle: {
  31. color: 'rgba(255, 129, 109, 0.1)',
  32. width: 1 //这里是为了突出显示加上的
  33. }
  34. },
  35. axisLabel: {
  36. textStyle: {
  37. color: '#999',
  38. fontSize: 12
  39. }
  40. }
  41. },
  42. yAxis: [{
  43. show: false,
  44. splitNumber: 2,
  45. axisTick: {
  46. show: false
  47. },
  48. axisLine: {
  49. lineStyle: {
  50. color: 'rgba(255, 129, 109, 0.1)',
  51. width: 1 //这里是为了突出显示加上的
  52. }
  53. },
  54. axisLabel: {
  55. textStyle: {
  56. color: '#999'
  57. }
  58. },
  59. splitArea: {
  60. areaStyle: {
  61. color: 'rgba(255,255,255,.5)'
  62. }
  63. },
  64. splitLine: {
  65. show: true,
  66. lineStyle: {
  67. color: 'rgba(255, 129, 109, 0.1)',
  68. width: 0.5,
  69. type: 'dashed'
  70. }
  71. }
  72. }],
  73. series: [{
  74. type: 'pictorialBar',
  75. barCategoryGap: '0%',
  76. symbol: 'path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z',
  77. label: {
  78. show: true,
  79. position: 'top',
  80. distance: 15,
  81. color: '#DB5E6A',
  82. fontWeight: 'bolder',
  83. fontSize: 16,
  84. },
  85. itemStyle: {
  86. normal: {
  87. color: {
  88. type: 'linear',
  89. x: 0,
  90. y: 0,
  91. x2: 0,
  92. y2: 1,
  93. colorStops: [{
  94. offset: 0,
  95. color: 'rgba(232, 94, 106, .8)' // 0% 处的颜色
  96. },
  97. {
  98. offset: 1,
  99. color: 'rgba(232, 94, 106, .1)' // 100% 处的颜色
  100. }
  101. ],
  102. global: false // 缺省为 false
  103. }
  104. },
  105. emphasis: {
  106. opacity: 1
  107. }
  108. },
  109. data: [],
  110. z: 10
  111. }]
  112. };
  113. block3.setOption(block3Opt);
  114. $.ajax({
  115. url: ajaxBaseUrl + "data/important-person.json",
  116. dataType: "json"
  117. }).done(function () {
  118. $("#block3").addClass("chart-done");
  119. }).done(function (data) {
  120. const xData = [];
  121. const yData = [];
  122. for (let i in data) {
  123. xData.push(data[i].name);
  124. yData.push(data[i].value);
  125. }
  126. block3.setOption({
  127. xAxis: {
  128. data: xData
  129. },
  130. series: [{
  131. name: "人员数量",
  132. data: yData
  133. }]
  134. });
  135. }).fail(function (jqXHR) {
  136. console.log("Ajax Fail: ", jqXHR.status, jqXHR.statusText);
  137. });
  138. }