1.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div id="myChartindex1" style="width: 100%; height: 100%;"></div>
  3. </template>
  4. <script>
  5. import {oldPersonOldType} from '../../api'
  6. //圆角柱状图
  7. import echarts from 'echarts'
  8. export default {
  9. data() {
  10. return {
  11. dataArr: [],
  12. colorArr: [
  13. {color1: '#9db9ff', color2: '#00f'},
  14. {color1: '#ffe49e', color2: '#ffb300'}
  15. ],
  16. myChart: null
  17. }
  18. },
  19. methods: {
  20. async draw() {
  21. if (this.myChart != '' && this.myChart != null) {
  22. this.myChart.clear();
  23. }
  24. console.log("kokokokokokoko");
  25. const result = await oldPersonOldType({}, 'POST');
  26. this.dataArr = result;
  27. this.myChart = this.$echarts.init(document.getElementById('myChartindex1'));
  28. this.myChart.setOption({
  29. grid: {
  30. left: '0%',
  31. right: '0%',
  32. top: '22%',
  33. bottom: '20%'
  34. },
  35. xAxis: {
  36. type: 'category',
  37. data: this.dataArr.map((item) => item.label),
  38. axisTick: {
  39. show: false
  40. },
  41. axisLabel: {
  42. interval:0,
  43. margin:16,
  44. show: true,
  45. textStyle: {
  46. color: 'white',
  47. fontSize: this.fontSize(0.14)
  48. },
  49. },
  50. },
  51. yAxis: {
  52. type: 'value',
  53. axisLabel: {
  54. show: false
  55. },
  56. splitLine: {
  57. show: true,
  58. lineStyle: {
  59. color: ['#315070'],
  60. width: 1,
  61. type: 'solid'
  62. }
  63. },
  64. axisLine: {
  65. show: false
  66. },
  67. axisTick: {
  68. show: false
  69. },
  70. },
  71. series: [
  72. {
  73. data: this.dataArr.map((item) => item.value),
  74. type: 'bar',
  75. barWidth: 14,
  76. itemStyle: {
  77. emphasis: {
  78. barBorderRadius: 7
  79. },
  80. normal: {
  81. barBorderRadius: 7,
  82. color: (params) => {
  83. return new echarts.graphic.LinearGradient(
  84. 0, 0, 0, 1,
  85. [
  86. {
  87. offset: 0,
  88. color: this.colorArr[params.dataIndex % 2 == 0 ? 0 : 1].color1
  89. },
  90. {
  91. offset: 1,
  92. color: this.colorArr[params.dataIndex % 2 == 0 ? 0 : 1].color2
  93. }
  94. ]
  95. )
  96. }
  97. }
  98. },
  99. label: {
  100. show: true,
  101. position: 'top',
  102. formatter: '{c}人',
  103. offset: [0, -10],
  104. color: '#fff',
  105. textStyle: {
  106. color: 'white',
  107. fontSize: this.fontSize(0.13)
  108. },
  109. },
  110. z: 1
  111. },
  112. {
  113. type: 'line',
  114. data: this.dataArr.map((item) => item.value),
  115. symbol: (params, item) => {
  116. return item.dataIndex % 2 == 0 ? `image://${require("../../assets/index/q1.png")}` : `image://${require("../../assets/index/q2.png")}`;
  117. },
  118. symbolSize: [19, 19],
  119. lineStyle: {
  120. color: 'rgba(255, 165, 0, 1)',
  121. width: 1,
  122. type: 'dashed'
  123. },
  124. z: 2
  125. }
  126. ]
  127. });
  128. },
  129. fontSize(res) {
  130. let clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  131. if (!clientWidth) return;
  132. let fontSize = 100 * (clientWidth / 1920);
  133. return res * fontSize;
  134. }
  135. },
  136. mounted() {
  137. // this.draw();
  138. }
  139. }
  140. </script>
  141. <style type="text/css">
  142. </style>