chart_b.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div class="chart_b">
  3. <div id="chart_b" style="width: 80%;height:400px;"></div>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. orgOptions: {},
  11. // subtext: "副标题"
  12. };
  13. },
  14. created() {},
  15. props: {
  16. dateArr:{type:Array},
  17. data:{type:Array}
  18. },
  19. watch: {
  20. dateArr(nVal,oVal) {
  21. this.drawChart();
  22. }
  23. },
  24. mounted() {
  25. this.drawChart();
  26. },
  27. methods: {
  28. drawChart() {
  29. // 基于准备好的dom,初始化echarts实例
  30. let myChart = this.$echarts.init(document.getElementById("chart_b"));
  31. // 指定图表的配置项和数据
  32. let option = {
  33. title: {
  34. text: "环境温度",
  35. // subtext: this.subtext,
  36. left: 100
  37. },
  38. tooltip: {
  39. trigger: "axis"
  40. },
  41. toolbox: {
  42. show: true,
  43. feature: {
  44. dataZoom: {
  45. yAxisIndex: "none"
  46. },
  47. dataView: { readOnly: false },
  48. magicType: { type: ["line", "bar"] },
  49. restore: {},
  50. saveAsImage: {}
  51. }
  52. },
  53. color: {
  54. type: "linear",
  55. x: 0,
  56. y: 0,
  57. x2: 0,
  58. y2: 1,
  59. colorStops: [
  60. {
  61. offset: 0,
  62. color: "red" // 0% 处的颜色
  63. },
  64. {
  65. offset: 1,
  66. color: "blue" // 100% 处的颜色
  67. }
  68. ]
  69. },
  70. xAxis: {
  71. type: "category",
  72. boundaryGap: false,
  73. data: this.dateArr || []
  74. },
  75. yAxis: {
  76. type: "value",
  77. axisLabel: {
  78. formatter: "{value} °C"
  79. },
  80. scale: true
  81. },
  82. series: [
  83. {
  84. name: "耳温",
  85. type: "line",
  86. // data: [32.5, 32.6, 32.4, 32.5, 32.4, 32.6, 32.4],
  87. data: this.data,
  88. markPoint: {
  89. data: [
  90. { type: "max", name: "最大值" },
  91. { type: "min", name: "最小值" }
  92. ]
  93. },
  94. markLine: {
  95. data: [{ type: "average", name: "平均值" }]
  96. }
  97. }
  98. ]
  99. };
  100. // 使用刚指定的配置项和数据显示图表。
  101. myChart.setOption(option);
  102. }
  103. }
  104. };
  105. </script>
  106. <style lang="scss" scoped>
  107. </style>