6.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <div id="c6" style="width: 100%;height: 100%;"></div>
  3. </template>
  4. <script>
  5. export default {
  6. name: "chart",
  7. props: {
  8. dataArr: {
  9. type: Array,
  10. default: () => {
  11. return [];
  12. }
  13. }
  14. },
  15. data() {
  16. return {};
  17. },
  18. mounted() {
  19. this.gatherers();
  20. },
  21. watch: {
  22. dataArr() {
  23. this.myChart.clear();
  24. this.gatherers();
  25. }
  26. },
  27. methods: {
  28. gatherers() {
  29. let dataArr = this.dataArr;
  30. let color = [
  31. ["rgba(254,196,0,0.15)", "rgba(254,196,0,1)"],
  32. ["rgba(105,218,123,0.15)", "rgba(19,205,215,1)"]
  33. ];
  34. let topColor = ["#FEC400", "#13CDD7"];
  35. let chartData = [];
  36. let chartName = [];
  37. let list = [];
  38. dataArr.forEach(function(item, index) {
  39. chartName.push(item.label);
  40. chartData.push({
  41. value: item.value,
  42. symbol: "circle",
  43. symbolPosition: "end",
  44. itemStyle: {
  45. normal: {
  46. color: topColor[index % 2]
  47. }
  48. }
  49. });
  50. list.push({
  51. value: item.value,
  52. symbolOffset: [0, 0],
  53. symbol: "path://M419.5,746.986L401,983h37Z",
  54. itemStyle: {
  55. normal: {
  56. color: {
  57. type: "linear",
  58. x: 0,
  59. y: 0,
  60. x2: 0,
  61. y2: 1,
  62. colorStops: [
  63. {
  64. offset: 1,
  65. color: color[index % 2][0]
  66. },
  67. {
  68. offset: 0,
  69. color: color[index % 2][1]
  70. }
  71. ],
  72. globalCoord: false
  73. }
  74. }
  75. },
  76. label: {
  77. normal: {
  78. show: true,
  79. position: "top",
  80. offset: [0, 0],
  81. textStyle: {
  82. color: topColor[index % 2],
  83. // fontWeight: 900,
  84. fontSize: 18
  85. }
  86. }
  87. }
  88. });
  89. });
  90. let myChart = this.$echarts.init(document.getElementById("c6"));
  91. this.myChart = myChart;
  92. // 绘制图表
  93. myChart.setOption({
  94. grid: {
  95. left: "5%",
  96. top: "22%",
  97. right: "12%",
  98. bottom: "8%",
  99. containLabel: true
  100. },
  101. title: [
  102. {
  103. text: "(万元)",
  104. left: "4%",
  105. bottom: "5%",
  106. textStyle: {
  107. fontWeight: 900,
  108. fontSize: 18,
  109. color: "#fff",
  110. textAlign: "center"
  111. }
  112. },
  113. // {
  114. // text: "(日)",
  115. // right: "10%",
  116. // bottom: "5%",
  117. // textStyle: {
  118. // fontWeight: 900,
  119. // fontSize: 18,
  120. // color: "#8998aa",
  121. // textAlign: "center"
  122. // }
  123. // }
  124. ],
  125. xAxis: [
  126. {
  127. type: "category",
  128. offset: 5,
  129. axisTick: {
  130. show: false
  131. },
  132. axisLine: {
  133. show: true,
  134. lineStyle: {
  135. color: "#404b5f"
  136. }
  137. },
  138. axisLabel: {
  139. formatter: "{value}日",
  140. interval:0,
  141. textStyle: {
  142. color: "#fff",
  143. // fontWeight: 900,
  144. fontSize: 18
  145. }
  146. },
  147. data: chartName
  148. }
  149. ],
  150. yAxis: {
  151. type: "value",
  152. axisTick: {
  153. show: false
  154. },
  155. axisLine: {
  156. show: false
  157. },
  158. splitLine: {
  159. //网格线
  160. lineStyle: {
  161. color: "#07355a"
  162. },
  163. show: true //隐藏或显示
  164. },
  165. axisLabel: {
  166. show: true, //隐藏或显示
  167. textStyle: {
  168. color: "#fff",
  169. // fontWeight: 900,
  170. fontSize: 18
  171. }
  172. }
  173. },
  174. series: [
  175. {
  176. type: "pictorialBar",
  177. name: "案件归类",
  178. symbolSize: [30, "100%"],
  179. z: 10,
  180. data: list
  181. },
  182. {
  183. name: "top",
  184. type: "pictorialBar",
  185. symbolSize: [11, 11],
  186. symbolOffset: [0, 0],
  187. data: chartData,
  188. z: 20
  189. }
  190. ]
  191. });
  192. window.addEventListener("resize", function() {
  193. myChart.resize();
  194. });
  195. }
  196. },
  197. computed: {}
  198. };
  199. </script>
  200. <style scoped>
  201. </style>