7.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <div id="myChartold7" style="width: 100%; height: 100%; "></div>
  3. </template>
  4. <script>
  5. import { oldPersonVisitFrequency } from '../../api'
  6. export default {
  7. //老年人探访频次统计
  8. name: "OldPersonFrequencyCount",
  9. data() {
  10. return {
  11. dataArr: [],
  12. colorArr: [ 'rgba(0, 124, 255, 0.6)', 'rgba(129, 212, 255, 0.6)' ],
  13. myChart: null
  14. }
  15. },
  16. methods: {
  17. async draw() {
  18. const result = await oldPersonVisitFrequency({}, 'POST');
  19. this.dataArr = result;
  20. const arr = this.dataArr.reverse();
  21. let maxValue = arr[0].value;
  22. for(let i = 0; i < arr.length; i++) {
  23. if(maxValue < arr[i].value) {
  24. maxValue = arr[i].value;
  25. }
  26. }
  27. const seriesArr = [];
  28. for(let i = 0; i < arr.length; i++) {
  29. const d = arr[i];
  30. const bgArr = new Array(arr.length).fill({});
  31. bgArr[i] = { value: maxValue, symbolPosition: 'start' };
  32. seriesArr.push({
  33. type: 'pictorialBar',
  34. symbol: `image://${require("../../assets/oldStatistics/x.png")}`,
  35. symbolSize: ['100%', 15],
  36. symbolOffset: [0, 0],
  37. data: bgArr,
  38. label: {
  39. show: true,
  40. position: 'right',
  41. offset: [10, 2],
  42. distance: 0,
  43. color: 'rgba(0, 124, 255, 1)',
  44. fontSize: this.fontSize(0.15),
  45. formatter: `${d.value}人`
  46. },
  47. z: 2
  48. });
  49. const imgArr = new Array(arr.length).fill({});
  50. imgArr[i] = { value: d.value, symbolPosition: 'start' };
  51. seriesArr.push({
  52. type: 'pictorialBar',
  53. symbol: 'rect',
  54. symbolSize: ['100%', 15],
  55. itemStyle: {
  56. normal: {
  57. color: () => {
  58. return new this.$echarts.graphic.LinearGradient(
  59. 0, 0, 1, 0,
  60. [
  61. {offset: 0, color: this.colorArr[0]},
  62. {offset: 1, color: this.colorArr[1]}
  63. ]
  64. )
  65. }
  66. }
  67. },
  68. data: imgArr,
  69. z: 3
  70. });
  71. }
  72. if(this.myChart != null) {
  73. this.myChart.clear();
  74. }
  75. this.myChart = this.$echarts.init(document.getElementById('myChartold7'));
  76. this.myChart.setOption({
  77. grid: {
  78. top: '15%',
  79. bottom: '15%',
  80. right: '18%',
  81. left: '4%',
  82. containLabel: true
  83. },
  84. xAxis: {
  85. type: 'value',
  86. max: maxValue,
  87. axisTick: {
  88. show: false
  89. },
  90. axisLabel: {
  91. show: false
  92. },
  93. axisLine: {
  94. show: false
  95. },
  96. splitLine: {
  97. show: false
  98. }
  99. },
  100. yAxis: {
  101. type: 'category',
  102. data: arr.map((item) => item.label),
  103. axisTick: {
  104. show: false
  105. },
  106. axisLabel: {
  107. show: true,
  108. color: '#fff',
  109. fontWeight: 'bold',
  110. fontSize: this.fontSize(0.16),
  111. },
  112. axisLine: {
  113. show: true,
  114. lineStyle: {
  115. color: '#fff'
  116. }
  117. }
  118. },
  119. series: seriesArr
  120. });
  121. },
  122. fontSize(res) {
  123. let clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  124. if (!clientWidth) return;
  125. let fontSize = 100 * (clientWidth / 1920);
  126. return res * fontSize;
  127. }
  128. },
  129. mounted() {
  130. this.draw();
  131. }
  132. }
  133. </script>
  134. <style scoped>
  135. </style>