6.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div id="myChart66" style="width: 100%; height: 100%;"></div>
  3. </template>
  4. <script>
  5. import { oldPersonMind } from '../../api'
  6. export default {
  7. //老年人精神状态
  8. name: "OldPersonMentality",
  9. data() {
  10. return {
  11. dataArr: [],
  12. colorArr: ['#238aff','#ff0','#0f0'],
  13. myChart: null
  14. }
  15. },
  16. methods: {
  17. async draw() {
  18. const result = await oldPersonMind({}, 'POST');
  19. this.dataArr = result;
  20. const seriesArr = [];
  21. for(let i = 0; i < this.dataArr.length; i++) {
  22. const d = this.dataArr[i];
  23. const imgArr = new Array(this.dataArr.length).fill({});
  24. imgArr[i] = { value: parseInt(d.value) };
  25. seriesArr.push({
  26. type: 'pictorialBar',
  27. barWidth: 40,
  28. symbol: `image://${require('../../assets/PatrolmanStatistics/sjx-' + i + '.png')}`,
  29. itemStyle: {
  30. normal: {
  31. color: (params) => {
  32. return this.colorArr[params.dataIndex];
  33. }
  34. }
  35. },
  36. label: {
  37. show: true,
  38. position: 'top',
  39. textStyle: {
  40. fontSize: 18
  41. },
  42. fontWeight: 'bold',
  43. offset: [0, 0],
  44. formatter: '{c}%'
  45. },
  46. data: imgArr
  47. });
  48. }
  49. this.myChart = this.$echarts.init(document.getElementById('myChart66'));
  50. this.myChart.setOption({
  51. xAxis: {
  52. type: 'category',
  53. data: this.dataArr.map((item) => item.label ),
  54. splitLine: {
  55. show: false
  56. },
  57. axisLine: {
  58. show: false
  59. },
  60. axisLabel: {
  61. show: true,
  62. color: '#fff',
  63. fontWeight: 'bold',
  64. fontSize: 15
  65. },
  66. axisTick: {
  67. show: false
  68. }
  69. },
  70. yAxis: {
  71. type: 'value',
  72. splitLine: {
  73. show: false
  74. },
  75. axisLine: {
  76. show: false
  77. },
  78. axisLabel: {
  79. show: false
  80. },
  81. axisTick: {
  82. show: false
  83. }
  84. },
  85. series: seriesArr
  86. });
  87. }
  88. },
  89. watch: {
  90. data() {
  91. this.myChart.destroy();
  92. this.draw();
  93. }
  94. },
  95. mounted() {
  96. this.draw();
  97. }
  98. }
  99. </script>
  100. <style scoped>
  101. </style>