9.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <div id="myChart9" style="width: 100%; height: 100%;"></div>
  3. </template>
  4. <script>
  5. import { oldPersonLive } from '../../api'
  6. export default {
  7. //老年人居住环境
  8. name: "OldPersonLiveCount",
  9. data() {
  10. return {
  11. dataArr: [],
  12. myChart: null
  13. }
  14. },
  15. methods: {
  16. async draw() {
  17. const result = await oldPersonLive({}, 'POST');
  18. this.dataArr = result;
  19. this.myChart = this.$echarts.init(document.getElementById('myChart9'));
  20. this.myChart.setOption({
  21. grid:{
  22. top:"15%",
  23. left:"18%",
  24. right:"5%",
  25. },
  26. xAxis: {
  27. type: 'category',
  28. boundaryGap: true,
  29. data: this.dataArr.map((item) => {
  30. return item.label;
  31. }),
  32. splitLine: {
  33. show: false
  34. },
  35. axisLine: {
  36. show: false,
  37. lineStyle: {
  38. color: '#fff'
  39. }
  40. },
  41. axisLabel: {
  42. show: true,
  43. fontSize: this.fontSize(0.16)
  44. },
  45. axisTick: {
  46. show: false
  47. }
  48. },
  49. yAxis: {
  50. type: 'value',
  51. max: 100,
  52. splitLine: {
  53. show: false
  54. },
  55. axisLine: {
  56. show: false,
  57. lineStyle: {
  58. color: '#fff'
  59. }
  60. },
  61. axisTick: {
  62. show: false
  63. },
  64. axisLabel: {
  65. show: true,
  66. formatter: '{value}%',
  67. fontSize: this.fontSize(0.16)
  68. }
  69. },
  70. series: [
  71. {
  72. type: 'line',
  73. smooth: true,
  74. areaStyle: {
  75. color: {
  76. type: 'linear',
  77. x: 0,
  78. y: 0,
  79. x2: 0,
  80. y2: 1,
  81. colorStops: [{
  82. offset: 0, color: 'rgba(0, 144, 255, 0.2)' // 0% 处的颜色
  83. }, {
  84. offset: 1, color: 'rgba(215, 255, 255, 0.2)' // 100% 处的颜色
  85. }],
  86. global: false // 缺省为 false
  87. }
  88. },
  89. symbol: `image://${require('../../assets/PatrolmanStatistics/y.png')}`,
  90. symbolSize: [10, 10],
  91. data: this.dataArr.map((item) => {
  92. return parseFloat(item.value);
  93. }),
  94. label: {
  95. show: true,
  96. formatter: '{c}%',
  97. color: '#fff',
  98. fontSize: 12
  99. },
  100. itemStyle: {
  101. color: new this.$echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  102. offset: 0,
  103. color: '#96c2ff'
  104. }, {
  105. offset: 1,
  106. color: '#0090ff'
  107. }]),
  108. },
  109. lineStyle: {
  110. width: 2
  111. }
  112. }
  113. ]
  114. });
  115. },
  116. fontSize(res) {
  117. let clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  118. if (!clientWidth) return;
  119. let fontSize = 100 * (clientWidth / 1920);
  120. return res * fontSize;
  121. }
  122. },
  123. watch: {
  124. data() {
  125. this.myChart.destroy();
  126. this.draw();
  127. }
  128. },
  129. mounted() {
  130. this.draw();
  131. }
  132. }
  133. </script>
  134. <style scoped>
  135. </style>