midLeft.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <div :class="className" :style="{height:height,width:width}">
  3. </div>
  4. </template>
  5. <script>
  6. import * as echarts from 'echarts';
  7. export default {
  8. props: {
  9. className: {
  10. type: String,
  11. default: 'chart'
  12. },
  13. width: {
  14. type: String,
  15. default: '100%'
  16. },
  17. height: {
  18. type: String,
  19. default: '350px'
  20. },
  21. autoResize: {
  22. type: Boolean,
  23. default: true
  24. },
  25. chartData: {
  26. type: Object,
  27. default:{}
  28. }
  29. },
  30. data() {
  31. return {
  32. chart: null
  33. }
  34. },
  35. watch: {
  36. chartData: {
  37. deep: true,
  38. handler(val) {
  39. this.setOptions(val)
  40. }
  41. }
  42. },
  43. mounted() {
  44. this.$nextTick(() => {
  45. this.initChart()
  46. })
  47. },
  48. beforeDestroy() {
  49. if (!this.chart) {
  50. return
  51. }
  52. this.chart.dispose()
  53. this.chart = null
  54. },
  55. methods: {
  56. initChart() {
  57. this.chart = echarts.init(this.$el, 'macarons')
  58. this.setOptions(this.chartData)
  59. },
  60. setOptions() {
  61. this.chart.setOption({
  62. // backgroundColor: "#041139",
  63. color: "#04CFE4",
  64. grid: {
  65. top: 80,
  66. left: 60,
  67. right: 40,
  68. bottom: 60
  69. },
  70. xAxis: {
  71. type: 'category',
  72. axisTick: false,
  73. axisLabel: {
  74. interval: 0,
  75. color: '#fff',
  76. fontSize: 14
  77. },
  78. data: ['2025', '2026', '2027', '2028', '2029', '2030', '2031', '2032', '2033', '2034']
  79. },
  80. yAxis: {
  81. type: 'value',
  82. interval: 100,
  83. splitLine: false,
  84. axisLabel: {
  85. color: '#fff'
  86. }
  87. }, title: {
  88. text: '达到预估寿命极限的管道统计', // 标题内容 // 水平居中
  89. top: '7%',
  90. left: '3%', // 距离顶部5%
  91. textStyle: { // 文字样式
  92. color: '#fff',
  93. fontSize: 16,
  94. fontWeight: 'normal'
  95. }
  96. },
  97. series: [
  98. {
  99. data: [10, 20, 15, 52, 55, 54, 67, 76, 332, 73],
  100. type: "pictorialBar",
  101. symbol: "path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z",
  102. label: {
  103. show: true,
  104. color: '#fff',
  105. position: 'top'
  106. }
  107. }
  108. ]
  109. })
  110. }
  111. }
  112. }
  113. </script>