index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div style="width: 100%;height: 100%" >
  3. <div id="fpcharts"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import resize from '../../../../components/Charts/mixins/resize'
  8. import * as echarts from 'echarts';
  9. export default {
  10. mixins: [resize],
  11. watch: {
  12. drawData:{
  13. handler(newValue, oldValue) {
  14. this.draw(newValue.times, newValue.datas,newValue.cap)
  15. },
  16. deep: true
  17. },
  18. resizeKey:function(newQuestion, oldQuestion){
  19. if(this.chart !=null){
  20. this.chart.resize();
  21. }
  22. }
  23. },
  24. props: {
  25. drawData:{
  26. type:Object,
  27. },
  28. resizeKey:{
  29. type:Number
  30. }
  31. },
  32. data() {
  33. return {
  34. chart: null,
  35. }
  36. },
  37. mounted() {
  38. },
  39. beforeDestroy() {
  40. if (!this.chart) {
  41. return
  42. }
  43. this.chart.dispose()
  44. this.chart = null
  45. },
  46. methods: {
  47. draw(timeaxis,realpower,cap) {
  48. console.log(timeaxis.length)
  49. this.chart = echarts.init(document.getElementById('fpcharts'))
  50. var option ={
  51. title: {
  52. top: 20,
  53. text: '短期预测实时查询',
  54. textStyle: {
  55. fontWeight: 'normal',
  56. fontSize: 16,
  57. },
  58. left: '1%'
  59. },
  60. tooltip: {
  61. trigger: 'axis',
  62. axisPointer: {
  63. lineStyle: {
  64. color: '#57617B'
  65. }
  66. }
  67. },
  68. legend: {
  69. top: 20,
  70. icon: 'rect',
  71. itemWidth: 14,
  72. itemHeight: 5,
  73. itemGap: 13,
  74. data: ['实时短期预测'],
  75. right: '4%',
  76. textStyle: {
  77. fontSize: 12,
  78. }
  79. },
  80. dataZoom: [{
  81. show: true,
  82. realtime: true,
  83. left:"15%",
  84. right:"15%",
  85. textStyle:{
  86. color:"#ffffff"
  87. }
  88. }, {
  89. type: 'inside'
  90. }],
  91. grid: {
  92. top: 100,
  93. left: '2%',
  94. right: '2%',
  95. bottom: '10%',
  96. containLabel: true
  97. },
  98. xAxis: {
  99. type: 'category',
  100. data: timeaxis
  101. },
  102. yAxis: {
  103. type: 'value',
  104. name: '(MW)',
  105. },
  106. series: [
  107. {
  108. name: '实时短期预测',
  109. data: realpower,
  110. type: 'line',
  111. smooth: true,
  112. showSymbol: false
  113. }
  114. ]
  115. }
  116. option.yAxis[0] = cap
  117. this.chart.setOption(option,true)
  118. },
  119. }
  120. }
  121. </script>
  122. <style scoped>
  123. #fpcharts{
  124. width: 100%;
  125. height:calc(80vh - 50px);
  126. }
  127. </style>