<!--
* @Description:
* @Version: 1.0
* @Author:
* @Date: 2022-09-15 14:56:15
-->
<template>
<div :id="chartRef" :style="{ width: '100%', height: '100%' }"></div>
</template>
<script lang="ts" setup>
import { ref, reactive, onMounted, watch, computed, toRefs } from "vue";
import * as echarts from "echarts";
import { uuid } from "vue-uuid";
const props = defineProps({
xaxisData: {
type: Array,
},
yaxisData: {
type: Array,
},
});
const chartRef = ref<any>(1);
chartRef.value = uuid.v1().replace(/-/g, "");
const setOptions = computed(() => {
let option = {
tooltip: {
trigger: "axis",
},
yAxis: {
type: "value",
},
xAxis: {
type: "category",
data: props.xaxisData,
},
series: props.yaxisData,
};
return option;
});
var BarChart: echarts.ECharts;
function initChart() {
BarChart.dispose();
BarChart = echarts.init(
document.getElementById(chartRef.value) as HTMLElement
);
BarChart.setOption(setOptions.value);
document.getElementById(chartRef.value).onresize = function () {
BarChart.resize();
};
}
onMounted(() => {
BarChart = echarts.init(
document.getElementById(chartRef.value) as HTMLElement
);
initChart();
});
watch([props], () => {
initChart();
});
</script>
<style scoped></style>
vue3中使用echarts,动态更新X、Y轴数据
转载请注明出处或者链接地址:https://www.qianduange.cn//article/15747.html
发布的文章
C#解析JSON的常用库--Newtonsoft.Json
2024-11-30 11:11:42
jsonfield 项目常见问题解决方案
2024-11-30 11:11:42
【SpringMVC】_SpringMVC项目返回HTML与JSON
2024-11-30 11:11:41
BugJson因为json格式问题OOM怎么办
2024-11-30 11:11:41
python 解读JSON文件,一文搞懂!
2024-11-30 11:11:40
Redisson同时使用jackson、fastjson、kryo、protostuff序列化(含效率对比)
2024-11-30 11:11:40
开源项目“Pretty JSON”安装与配置完全指南
2024-11-30 11:11:39
2024年前端最新Nodejs基础之包管理工具npm(二)(2),微软面试题及答案
2024-11-30 11:11:39
解决全局安装pnpm后无法使用的问题
2024-11-30 11:11:39
安装Nodejs后,npm无法使用
2024-11-30 11:11:38
大家推荐的文章