Eb.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div class="Eb">
  3. <div id="Eb" style="width: 70%;height:400px;"></div>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: "Eb",
  9. props: { EValue: Array },
  10. data() {
  11. return {
  12. timeArr: [],
  13. dataArr1: [],
  14. dataArr2: []
  15. };
  16. },
  17. watch: {
  18. EValue(v) {
  19. this.timeArr = [];
  20. this.dataArr1 = [];
  21. this.dataArr2 = [];
  22. v.forEach(item => {
  23. this.timeArr.push(item["name"]);
  24. this.dataArr1.push(item["pregnantCount"]);
  25. this.dataArr2.push(item["deliveryCount"]);
  26. });
  27. this.drawChart();
  28. }
  29. },
  30. created() {},
  31. mounted() {
  32. this.drawChart();
  33. },
  34. methods: {
  35. drawChart() {
  36. // 基于准备好的dom,初始化echarts实例
  37. let myChart = this.$echarts.init(document.getElementById("Eb"));
  38. // 指定图表的配置项和数据
  39. let option = {
  40. title: {
  41. text: "怀孕分娩数",
  42. left: "center",
  43. left: 100
  44. },
  45. legend: {
  46. orient: "horizontal",
  47. bottom: 10,
  48. data: ["配种", "分娩"]
  49. },
  50. color: ["#3398DB"],
  51. tooltip: {
  52. trigger: "axis",
  53. axisPointer: {
  54. // 坐标轴指示器,坐标轴触发有效
  55. type: "line" // 默认为直线,可选为:'line' | 'shadow'
  56. }
  57. },
  58. toolbox: {
  59. show: true,
  60. feature: {
  61. dataView: { show: true, readOnly: true },
  62. magicType: { show: true, type: ["line", "bar"] },
  63. restore: { show: true },
  64. saveAsImage: { show: true }
  65. }
  66. },
  67. grid: {
  68. left: "10%",
  69. right: "10%",
  70. bottom: "13%",
  71. containLabel: true
  72. },
  73. xAxis: [
  74. {
  75. type: "category",
  76. data: this.timeArr,
  77. axisTick: {
  78. alignWithLabel: true
  79. }
  80. }
  81. ],
  82. yAxis: [
  83. {
  84. type: "value",
  85. scale: true
  86. }
  87. ],
  88. series: [
  89. {
  90. name: "配种",
  91. type: "bar",
  92. barWidth: "25%",
  93. data: this.dataArr1,
  94. encode: {
  95. x: "amount",
  96. y: "product"
  97. },
  98. markPoint: {
  99. data: [
  100. { type: "max", name: "最大值" },
  101. { type: "min", name: "最小值" }
  102. ]
  103. },
  104. markLine: {
  105. data: [{ type: "average", name: "平均值" }]
  106. }
  107. },
  108. {
  109. name: "分娩",
  110. type: "bar",
  111. barWidth: "25%",
  112. data: this.dataArr2,
  113. color: ["#4CCA73"],
  114. encode: {
  115. x: "amount",
  116. y: "product"
  117. },
  118. markPoint: {
  119. data: [
  120. { type: "max", name: "最大值" },
  121. { type: "min", name: "最小值" }
  122. ]
  123. },
  124. markLine: {
  125. data: [{ type: "average", name: "平均值" }]
  126. }
  127. }
  128. ]
  129. };
  130. // 使用刚指定的配置项和数据显示图表。
  131. myChart.setOption(option);
  132. }
  133. }
  134. };
  135. </script>
  136. <style lang="scss" scoped>
  137. </style>