1.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. const result = await oldPersonOldType({}, 'POST');
  25. this.dataArr = result;
  26. this.myChart = this.$echarts.init(document.getElementById('myChartindex1'));
  27. this.myChart.setOption({
  28. grid: {
  29. left:'0%',
  30. right:'0%',
  31. top:'22%',
  32. bottom:'20%'
  33. },
  34. xAxis: {
  35. type: 'category',
  36. data: this.dataArr.map((item) => item.label),
  37. axisTick: {
  38. show: false
  39. },
  40. axisLabel: {
  41. show: true,
  42. textStyle: {
  43. color: 'white',
  44. fontSize : this.fontSize(0.16)
  45. },
  46. },
  47. },
  48. yAxis: {
  49. type: 'value',
  50. axisLabel: {
  51. show: false
  52. },
  53. splitLine: {
  54. show: true,
  55. lineStyle:{
  56. color: ['#315070'],
  57. width: 1,
  58. type: 'solid'
  59. }
  60. },
  61. axisLine: {
  62. show: false
  63. },
  64. axisTick: {
  65. show: false
  66. },
  67. },
  68. series: [
  69. {
  70. data: this.dataArr.map((item) => item.value),
  71. type: 'bar',
  72. barWidth: 14,
  73. itemStyle: {
  74. emphasis: {
  75. barBorderRadius: 7
  76. },
  77. normal: {
  78. barBorderRadius: 7,
  79. color: (params) => {
  80. return new echarts.graphic.LinearGradient(
  81. 0, 0, 0, 1,
  82. [
  83. {offset: 0, color: this.colorArr[params.dataIndex % 2 == 0 ? 0 : 1].color1},
  84. {offset: 1, color: this.colorArr[params.dataIndex % 2 == 0 ? 0 : 1].color2}
  85. ]
  86. )
  87. }
  88. }
  89. },
  90. label: {
  91. show: true,
  92. position: 'top',
  93. offset: [0, -10],
  94. color: '#fff',
  95. textStyle: {
  96. color: 'white',
  97. fontSize : this.fontSize(0.16)
  98. },
  99. },
  100. z: 1
  101. },
  102. {
  103. type: 'line',
  104. data: this.dataArr.map((item) => item.value),
  105. symbol: (params, item) => {
  106. return item.dataIndex % 2 == 0 ? `image://${require("../../assets/index/q1.png")}` : `image://${require("../../assets/index/q2.png")}`;
  107. },
  108. symbolSize: [19, 19],
  109. lineStyle: {
  110. color: 'rgba(255, 165, 0, 1)',
  111. width: 1,
  112. type: 'dashed'
  113. },
  114. z: 2
  115. }
  116. ]
  117. });
  118. },
  119. fontSize(res) {
  120. let clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  121. if (!clientWidth) return;
  122. let fontSize = 100 * (clientWidth / 1920);
  123. return res * fontSize;
  124. }
  125. },
  126. mounted() {
  127. this.draw();
  128. }
  129. }
  130. </script>
  131. <style type="text/css">
  132. </style>