coldTrendChart.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <script>
  2. export default {
  3. data() {
  4. return {
  5. }
  6. },
  7. props: {
  8. height: Number,
  9. },
  10. mounted() {
  11. this.$nextTick(()=>{
  12. this.initChart()
  13. })
  14. },
  15. methods: {
  16. initChart() {
  17. let chart = this.$echarts.init(this.$refs.myChart)
  18. let defaultOption = {
  19. legend: {
  20. data: [
  21. '用冷量',
  22. '温度',
  23. ]
  24. },
  25. grid: {
  26. left: '0%', //默认10%
  27. right: '0%', //默认10%
  28. bottom: '15%', //默认60
  29. top: '15%',
  30. containLabel: true
  31. //grid区域是否包含坐标轴的刻度标签
  32. },
  33. xAxis: {
  34. data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
  35. },
  36. yAxis: [
  37. {
  38. name: '冷量(kWh)',
  39. type: 'value',
  40. nameTextStyle: {
  41. padding: [10, 0, 10, 0]
  42. },
  43. },
  44. {
  45. name: '温度(℃)',
  46. type: 'value',
  47. nameTextStyle: {
  48. padding: [10, 0, 10, -12]
  49. },
  50. },
  51. ],
  52. dataZoom: [
  53. {
  54. start: 0,
  55. end: 100,
  56. height: 16,
  57. }
  58. ],
  59. tooltip: {
  60. trigger: 'axis',
  61. axisPointer: {
  62. type: 'shadow'
  63. },
  64. textStyle: {
  65. color: '#fff',
  66. align: 'left',
  67. fontSize: 14
  68. },
  69. axisLine: {//x坐标轴轴线
  70. show: true,
  71. lineStyle: {//x坐标轴轴线样式
  72. color: '#000',//'#ccc' | 'rgb(128, 128, 128)' | 'rgba(128, 128, 128, 0.5)',设置标签颜色
  73. }
  74. },
  75. backgroundColor: 'rgba(0,0,0,0.8)',
  76. },
  77. series: [
  78. {
  79. name: '用冷量',
  80. data: [35, 71, 51, 32, 28, 66, 42, 42, 87, 34, 88, 45],
  81. type: 'line',
  82. stack: 'a',
  83. yAxisIndex:0,
  84. smooth: true,
  85. lineStyle: {
  86. color: "#62CC97",
  87. width: 1,
  88. },
  89. itemStyle: {
  90. color: '#62CC97'
  91. },
  92. emphasis: {
  93. scale:1.5
  94. }
  95. },
  96. {
  97. name: '温度',
  98. data: [23, 23, 17, 19, 20, 24, 23, 22, 22, 18, 25, 16],
  99. type: 'line',
  100. stack: 'b',
  101. smooth: true,
  102. yAxisIndex:1,
  103. lineStyle: {
  104. color: "#FDB456",
  105. width: 1,
  106. },
  107. itemStyle: {
  108. color: '#FDB456'
  109. },
  110. emphasis: {
  111. scale:1.5
  112. },
  113. },
  114. ]
  115. };
  116. //Object.assign(defaultOption, this.option)
  117. chart.setOption(defaultOption)
  118. }
  119. }
  120. }
  121. </script>
  122. <template>
  123. <div style="width: 100%" :style="{height: height+'px'}" ref="myChart"></div>
  124. </template>
  125. <style lang="less" scoped>
  126. </style>