jt-echarts.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div ref="echarts" style="width: 100%;height: 100%;"></div>
  3. </template>
  4. <script>
  5. import * as echarts from "echarts";
  6. import 'echarts-liquidfill';
  7. export default {
  8. props: {
  9. isAxisChart: {
  10. type: Boolean,
  11. default: true,
  12. },
  13. chartData: {
  14. type: Object,
  15. default:{}
  16. },
  17. },
  18. data() {
  19. return {
  20. axisOption: {
  21. legend: {
  22. // 图例文字颜色
  23. textStyle: {
  24. color: "#333",
  25. },
  26. },
  27. grid: {
  28. left: "20%",
  29. },
  30. // 提示框
  31. tooltip: {
  32. trigger: "axis",
  33. },
  34. xAxis: {
  35. type: "category", // 类目轴
  36. data: [],
  37. axisLine: {
  38. lineStyle: {
  39. color: "#17b3a3",
  40. },
  41. },
  42. axisLabel: {
  43. interval: 0,
  44. color: "#333",
  45. },
  46. },
  47. yAxis: [
  48. {
  49. type: "value",
  50. axisLine: {
  51. lineStyle: {
  52. color: "#17b3a3",
  53. },
  54. },
  55. },
  56. ],
  57. color: ["#2ec7c9", "#b6a2de"],
  58. series: [],
  59. },
  60. normalOption: {
  61. tooltip: {
  62. trigger: "item",
  63. },
  64. color: ["#0f78f4", "#dd536b", "#9462e5", "#a6a6a6", "#e1bb22", "#39c362", "#3ed1cf"],
  65. series: [],
  66. },
  67. echart: "",
  68. };
  69. },
  70. methods: {
  71. initChart() {
  72. this.initChartData();
  73. if (this.echart) {
  74. this.echart.setOption(this.options);
  75. } else {
  76. this.echart = echarts.init(this.$refs.echarts);
  77. this.echart.setOption(this.options);
  78. }
  79. },
  80. initChartData() {
  81. if (this.isAxisChart) {
  82. this.axisOption = this.chartData
  83. // this.axisOption.series = this.chartData
  84. } else {
  85. this.normalOption.series = this.chartData
  86. }
  87. },
  88. },
  89. watch: {
  90. chartData: {
  91. handler: function () {
  92. this.initChart();
  93. },
  94. deep: true,
  95. },
  96. },
  97. computed: {
  98. options() {
  99. return this.isAxisChart ? this.axisOption : this.normalOption;
  100. },
  101. },
  102. mounted() {
  103. }
  104. };
  105. </script>
  106. <style scoped>
  107. </style>