chart_b.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div class="chart_b">
  3. <div id="chart_b" style="width: 75%;height:300px;"></div>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: "chart_b",
  9. props: {
  10. },
  11. data() {
  12. return {
  13. };
  14. },
  15. created() {
  16. },
  17. mounted() {
  18. this.drawChart();
  19. },
  20. methods: {
  21. drawChart() {
  22. // 基于准备好的dom,初始化echarts实例
  23. let myChart = this.$echarts.init(
  24. document.getElementById('chart_b')
  25. );
  26. // 指定图表的配置项和数据
  27. let option = {
  28. title: {
  29. text: "日温度",
  30. subtext: "纯属虚构",
  31. left: 100
  32. },
  33. tooltip: {
  34. trigger: "axis"
  35. },
  36. toolbox: {
  37. show: true,
  38. feature: {
  39. dataZoom: {
  40. yAxisIndex: "none"
  41. },
  42. dataView: { readOnly: true },
  43. magicType: { type: ["line", "bar"] },
  44. restore: {},
  45. saveAsImage: {}
  46. }
  47. },
  48. color: {
  49. type: "linear",
  50. x: 0,
  51. y: 0,
  52. x2: 0,
  53. y2: 1,
  54. colorStops: [
  55. {
  56. offset: 0,
  57. // color: "rgb(251,132,32)" // 0% 处的颜色
  58. color: "rgb(14,182,195)" // 0% 处的颜色
  59. },
  60. {
  61. offset: 1,
  62. color: "rgb(14,182,195)" // 100% 处的颜色
  63. }
  64. ]
  65. },
  66. xAxis: {
  67. type: "category",
  68. boundaryGap: false,
  69. data: [
  70. "七小时前",
  71. "六小时前",
  72. "五小时前",
  73. "四小时前",
  74. "三小时前",
  75. "两小时前",
  76. "七小时前",
  77. "六小时前",
  78. "五小时前",
  79. "四小时前",
  80. "三小时前",
  81. "两小时前",
  82. "七小时前",
  83. "六小时前",
  84. "五小时前",
  85. "四小时前",
  86. "三小时前",
  87. "两小时前",
  88. "七小时前",
  89. "六小时前",
  90. "五小时前",
  91. "四小时前",
  92. "三小时前",
  93. "两小时前",
  94. "当前"
  95. ]
  96. },
  97. yAxis: {
  98. type: "value",
  99. axisLabel: {
  100. formatter: "{value} °C"
  101. },
  102. scale: true
  103. },
  104. series: [
  105. {
  106. name: "时间",
  107. type: "line",
  108. data: [32.6, 32.4, 32.5, 32.4, 32.5,32.66,32.6, 32.4, 32.4, 32.5, 32.4,32.52, 32.6, 32.4,32.69,32.52, 32.6, 32.4, 32.5,32.5, 32.4, 32.6, 32.4,32.6,32.52, 32.6, 32.4],
  109. markPoint: {
  110. data: [
  111. { type: "max", name: "最大值" },
  112. { type: "min", name: "最小值" }
  113. ]
  114. },
  115. markLine: {
  116. data: [{ type: "average", name: "平均值" }]
  117. }
  118. }
  119. ]
  120. };
  121. // 使用刚指定的配置项和数据显示图表。
  122. myChart.setOption(option);
  123. }
  124. }
  125. };
  126. </script>
  127. <style lang="scss" scoped>
  128. </style>