chart_a.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div class="chart_a">
  3. <div id="chart_a" 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. props: {
  15. dateArr:{type:Array},
  16. data:{type:Array}
  17. },
  18. created() {
  19. },
  20. watch: {
  21. dateArr(nVal,oVal) {
  22. this.drawChart();
  23. }
  24. },
  25. mounted() {
  26. this.drawChart();
  27. },
  28. methods: {
  29. drawChart() {
  30. // 基于准备好的dom,初始化echarts实例
  31. let myChart = this.$echarts.init(
  32. document.getElementById('chart_a')
  33. );
  34. // 指定图表的配置项和数据
  35. let option = {
  36. title: {
  37. text: "耳根温度",
  38. // subtext: this.subtext,
  39. left: 100
  40. },
  41. tooltip: {
  42. trigger: "axis"
  43. },
  44. toolbox: {
  45. show: true,
  46. feature: {
  47. dataZoom: {
  48. yAxisIndex: "none"
  49. },
  50. dataView: { readOnly: false },
  51. magicType: { type: ["line", "bar"] },
  52. restore: {},
  53. saveAsImage: {}
  54. }
  55. },
  56. color: {
  57. type: "linear",
  58. x: 0,
  59. y: 0,
  60. x2: 0,
  61. y2: 1,
  62. colorStops: [
  63. {
  64. offset: 0,
  65. color: "red" // 0% 处的颜色
  66. },
  67. {
  68. offset: 1,
  69. color: "blue" // 100% 处的颜色
  70. }
  71. ]
  72. },
  73. xAxis: {
  74. type: "category",
  75. boundaryGap: false,
  76. data: this.dateArr
  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: this.data,
  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>