barChart.vue 795 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <template>
  2. <div ref="chartDom" class="charts"></div>
  3. </template>
  4. <script setup>
  5. import { onMounted, ref } from "vue";
  6. import * as echarts from "echarts";
  7. import { barOption } from "./option/barOption.js";
  8. const props = defineProps ({
  9. styleName: {
  10. type: String,
  11. default: "styleName1",
  12. },
  13. });
  14. let chartDom = ref(null);
  15. let myChart = null;
  16. const options = ref(null);
  17. const initData = () => {
  18. barOption[props.styleName].xAxis.data = ["正常", "较大", "异常"];
  19. barOption[props.styleName].series[0].data = [33, 41, 43];
  20. options.value = barOption[props.styleName];
  21. myChart.setOption(options.value);
  22. };
  23. onMounted(() => {
  24. myChart = echarts.init(chartDom.value);
  25. initData();
  26. });
  27. </script>
  28. <style lang="scss" scoped>
  29. .charts {
  30. width: 100%;
  31. height: 100%;
  32. }
  33. </style>