IndicatorChart.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-11-22 15:10:07
  4. * @LastEditTime: 2022-01-06 10:07:04
  5. * @LastEditors: Please set LastEditors
  6. * @Description: 指标图
  7. * @FilePath: \hyyfScreen\src\views\Production\board\IndicatorChart.vue
  8. -->
  9. <template>
  10. <div :id="id + 'indicator'" class="indicator-chart"></div>
  11. </template>
  12. <script>
  13. export default {
  14. props: {
  15. ifPositive: {
  16. type: Boolean,
  17. required: true,
  18. },
  19. id: {
  20. required: true,
  21. },
  22. data: {
  23. type: Object,
  24. required: true,
  25. },
  26. },
  27. data() {
  28. return {
  29. myChart: null,
  30. };
  31. },
  32. methods: {
  33. init() {
  34. let color1 = "rgba(0, 255, 0, 0.7)";
  35. let color2 = "rgba(64, 218, 26, 0.5)";
  36. let color3 = "rgba(88, 165, 69, 0.3)";
  37. if (this.ifPositive) {
  38. color1 = "rgba(255, 0, 0, 0.7)";
  39. color2 = "rgba(216, 52, 52, 0.5)";
  40. color3 = "rgba(201, 85, 85, 0.3)";
  41. }
  42. let options = {
  43. grid: {
  44. top: "2%",
  45. left: "0",
  46. right: "0",
  47. bottom: "-20%",
  48. containLabel: true,
  49. },
  50. xAxis: {
  51. type: "category",
  52. boundaryGap: false,
  53. data: this.data.timeList,
  54. show: false,
  55. },
  56. yAxis: {
  57. type: "value",
  58. show: false,
  59. },
  60. series: [
  61. {
  62. data: this.data.dataList,
  63. type: "line",
  64. symbol: "none", // 隐藏拐点
  65. color: color1,
  66. areaStyle: {
  67. color: {
  68. type: "linear",
  69. x: 0,
  70. y: 0,
  71. x2: 0,
  72. y2: 1,
  73. colorStops: [
  74. {
  75. offset: 0,
  76. color: color1, // 100% 处的颜色
  77. },
  78. {
  79. offset: 0.5,
  80. color: color2, // 100% 处的颜色
  81. },
  82. {
  83. offset: 1,
  84. color: color3, // 0% 处的颜色
  85. },
  86. ],
  87. global: false, // 缺省为 false
  88. },
  89. },
  90. },
  91. ],
  92. };
  93. this.myChart.setOption(options, true);
  94. },
  95. },
  96. mounted() {
  97. this.myChart = this.$echarts.init(
  98. document.getElementById(this.id + "indicator")
  99. );
  100. this.init();
  101. },
  102. watch: {
  103. data: {
  104. handler() {
  105. this.init();
  106. },
  107. deep: true,
  108. },
  109. },
  110. };
  111. </script>
  112. <style scoped>
  113. .indicator-chart {
  114. width: 100%;
  115. height: 100%;
  116. }
  117. </style>