chart_b.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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: "red" // 0% 处的颜色
  58. },
  59. {
  60. offset: 1,
  61. color: "blue" // 100% 处的颜色
  62. }
  63. ]
  64. },
  65. xAxis: {
  66. type: "category",
  67. boundaryGap: false,
  68. data: [
  69. "七日前",
  70. "六日前",
  71. "五日前",
  72. "四日前",
  73. "三日前",
  74. "两日前",
  75. "当前"
  76. ]
  77. },
  78. yAxis: {
  79. type: "value",
  80. axisLabel: {
  81. formatter: "{value} °C"
  82. },
  83. scale: true
  84. },
  85. series: [
  86. {
  87. name: "时间",
  88. type: "line",
  89. data: [32.5, 32.6, 32.4, 32.5, 32.4, 32.6, 32.4],
  90. markPoint: {
  91. data: [
  92. { type: "max", name: "最大值" },
  93. { type: "min", name: "最小值" }
  94. ]
  95. },
  96. markLine: {
  97. data: [{ type: "average", name: "平均值" }]
  98. }
  99. }
  100. ]
  101. };
  102. // 使用刚指定的配置项和数据显示图表。
  103. myChart.setOption(option);
  104. }
  105. }
  106. };
  107. </script>
  108. <style lang="scss" scoped>
  109. </style>