直接上代码
var graphicConfig = [
{
type: "text",
left: "center",
top: "center",
style: {
text: "包日", // 初始化为空字符串
textAlign: "center",
fill: "#000",
fontSize: 14,
fontWeight: "bold",
},
id: "centerText", // 使用 id 标识这个元素,方便后续更新内容
},
];
var myChart = echarts.init(document.getElementById("userTypelistChat"));
myChart.setOption({
graphic: graphicConfig, // 初始化的 graphic 配置
});
myChart.on("mouseover", (params) => {
_this.name = params.name;
graphicConfig[0].style.text = _this.name; // 更新文本内容
myChart.setOption({
graphic: graphicConfig, // 更新图表配置
});
});