investYearChart.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div class="myChart" ref="myChart" :style="{height: height+'px'}"></div>
  3. </template>
  4. <script>
  5. import apiDashboard from "@/api/dashboard/apiDashboard";
  6. export default {
  7. data() {
  8. return {
  9. option: {
  10. color: ['#3AA7E6','#F8797E'],
  11. legend: {
  12. data: [
  13. '已使用时间',
  14. '标准年限',
  15. ]
  16. },
  17. grid: {
  18. left: '2%', //默认10%
  19. right: '2%', //默认10%
  20. bottom: '0%', //默认60
  21. top: '15%',
  22. containLabel: true
  23. //grid区域是否包含坐标轴的刻度标签
  24. },
  25. xAxis: {
  26. type: 'category',
  27. data: []
  28. },
  29. yAxis: [
  30. {
  31. name: '已使用时间',
  32. type: 'value',
  33. nameTextStyle: {
  34. padding: [10, 0, 10, 15]
  35. },
  36. },
  37. {
  38. type: 'value',
  39. name: '标准年限',
  40. nameTextStyle: {
  41. padding: [10, 20, 10, 0]
  42. },
  43. },
  44. ],
  45. tooltip: {
  46. trigger: 'axis',
  47. axisPointer: {
  48. type: 'shadow'
  49. },
  50. textStyle: {
  51. color: '#fff',
  52. align: 'left',
  53. fontSize: 14
  54. },
  55. axisLine: {//x坐标轴轴线
  56. show: true,
  57. lineStyle: {//x坐标轴轴线样式
  58. color: '#000',//'#ccc' | 'rgb(128, 128, 128)' | 'rgba(128, 128, 128, 0.5)',设置标签颜色
  59. }
  60. },
  61. backgroundColor: 'rgba(0,0,0,0.8)',
  62. },
  63. series: [
  64. {
  65. name: '已使用时间',
  66. data: [],
  67. type: 'bar',
  68. stack: 'A',
  69. barWidth: '30%',
  70. backgroundStyle: {
  71. color: 'rgba(180, 180, 180, 0.2)'
  72. }
  73. },
  74. {
  75. name: '标准年限',
  76. data: [],
  77. stack: 'B',
  78. yAxisIndex:1,
  79. type: 'line',
  80. }
  81. ]
  82. }
  83. }
  84. },
  85. props: {
  86. height: Number
  87. },
  88. mounted() {
  89. this.init()
  90. },
  91. methods: {
  92. init() {
  93. let chart = this.$echarts.init(this.$refs.myChart);
  94. this.chart = chart;
  95. chart.setOption(this.option);
  96. this.getData();
  97. },
  98. getData() {
  99. apiDashboard.getMoneyLifeData({}).then(res=>{
  100. let data = this.$util.dataUtil.covertDataToEcharts(res, ['serviceLife','standardLife'])
  101. this.$util.dataUtil.refreshEchartsData(this.chart, this.option, data)
  102. })
  103. }
  104. }
  105. }
  106. </script>
  107. <style lang="less" scoped>
  108. </style>