electricityUseChart.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. grid: {
  25. left: '0%', //默认10%
  26. right: '0%', //默认10%
  27. bottom: '15%', //默认60
  28. top: '15%',
  29. containLabel: true
  30. //grid区域是否包含坐标轴的刻度标签
  31. },
  32. xAxis: {
  33. data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
  34. },
  35. yAxis: [
  36. {
  37. name: 'kWh',
  38. type: 'value',
  39. nameTextStyle: {
  40. padding: [10, 0, 10, -12]
  41. },
  42. },
  43. ],
  44. dataZoom: [
  45. {
  46. start: 0,
  47. end: 100,
  48. height: 16,
  49. }
  50. ],
  51. tooltip: {
  52. trigger: 'axis',
  53. axisPointer: {
  54. type: 'shadow'
  55. },
  56. textStyle: {
  57. color: '#fff',
  58. align: 'left',
  59. fontSize: 14
  60. },
  61. axisLine: {//x坐标轴轴线
  62. show: true,
  63. lineStyle: {//x坐标轴轴线样式
  64. color: '#000',//'#ccc' | 'rgb(128, 128, 128)' | 'rgba(128, 128, 128, 0.5)',设置标签颜色
  65. }
  66. },
  67. backgroundColor: 'rgba(0,0,0,0.8)',
  68. },
  69. series: [
  70. {
  71. name: '用电量',
  72. data: [132, 107, 121, 152, 110, 192, 110, 167, 160, 141, 113, 137],
  73. type: 'line',
  74. stack: 'x',
  75. smooth: true,
  76. areaStyle: {
  77. color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  78. offset: 0,
  79. color: '#B0E5CB' // 0% 处的颜色
  80. }, {
  81. offset: 0.8,
  82. color: '#ffffff' // 100% 处的颜色
  83. }], false),
  84. },
  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. };
  98. //Object.assign(defaultOption, this.option)
  99. chart.setOption(defaultOption)
  100. }
  101. }
  102. }
  103. </script>
  104. <template>
  105. <div style="width: 100%" :style="{height: height+'px'}" ref="myChart"></div>
  106. </template>
  107. <style lang="less" scoped>
  108. </style>