const chartUse = echarts.init(document.getElementsByClassName("chart")[0]);
function chartFrameSwitch0() {
const stuckSeries = [
{
type: "gauge",
radius: "60%",
center: ["25%", "70%"],
data: [{ value: 50, groupId: "group1" }, {value: 80, groupId: "group2" }],
universalTransition: true,
animationDurationUpdate: 1000,
animationEasingUpdate: "quinticInOut"
},
{
type: "gauge",
radius: "60%",
center: ["75%", "70%"],
data: [{ value: 30, groupId: "group3" }, { value: 90, groupId: "group4" }],
universalTransition: true,
animationDurationUpdate: 1000,
animationEasingUpdate: "quinticInOut"
},
]
const baseOption0 = {
timeline: [
{
axisType: "category",
autoPlay: true,
playInterval: 1500,
data: ["2020", "2021", "2022"],
top: "35%",
left: "5%",
width: "40%",
height: "10%"
},
{
axisType: "value",
autoPlay: false,
playInterval: 1500,
data: [10, 20, 30],
top: "35%",
right: "5%",
width: "40%",
height: "10%"
},
],
tooltip: {},
legend: {},
grid: [
{
width: "40%",
height: "30%",
left: "5%",
top: "5%",
containLabel: true,
},
{
width: "40%",
height: "30%",
right: "5%",
top: "5%",
containLabel: true,
},
],
xAxis: [
{
type: "category",
gridIndex: 0,
data: ["Product A", "Product B", "Product C"],
},
{
type: "category",
gridIndex: 1,
data: ["Service A", "Service B", "Service C"],
},
],
yAxis: [
{ type: "value", gridIndex: 0 },
{ type: "value", gridIndex: 1 },
],
},
options0 = [
{
series: [
{
type: "line",
name: "Vendas",
xAxisIndex: 0,
yAxisIndex: 0,
data: [120, 200, 150]
},
{
type: "line",
name: "Vendas",
xAxisIndex: 1,
yAxisIndex: 1,
data: [80, 180, 220],
},
...stuckSeries
],
},
{
series: [
{
type: "line",
name: "Vendas",
xAxisIndex: 0,
yAxisIndex: 0,
data: [180, 250, 190],
},
{
type: "line",
name: "Vendas",
xAxisIndex: 1,
yAxisIndex: 1,
data: [50, 250, 110]
},
],
},
{
series: [
{
type: "line",
name: "Vendas",
xAxisIndex: 0,
yAxisIndex: 0,
data: [220, 300, 210],
},
{
type: "line",
name: "Vendas",
xAxisIndex: 1,
yAxisIndex: 1,
data: [220, 300, 210]
}
]
}
]
const option = {
baseOption: baseOption0,
options: options0
}
chartUse.setOption(option);
}
chartFrameSwitch0();
function chartFrameSwitch1 () {
const series0 = [
{
type: "pie",
center: ["25%", "70%"],
radius: "60%",
universalTransition: true,
animationDurationUpdate: 1000,
animationEasingUpdate: "quinticInOut",
data: [
{
name: "Test 1",
value: 80,
groupId: "group1"
},
{
name: "Test 2",
value: 90,
groupId: "group2"
}
]
},
{
type: "pie",
center: ["75%", "70%"],
radius: "60%",
universalTransition: true,
animationDurationUpdate: 1000,
animationEasingUpdate: "quinticInOut",
data: [
{
name: "Test 3",
value: 130,
groupId: "group3"
},
{
name: "Test 4",
value: 190,
groupId: "group4"
}
]
}
];
const option = {
series: series0
};
chartUse.setOption(option, {replaceMerge: ["timeline", "series", "xAxis", "yAxis"]} );
}
const gaugeClick = document.getElementsByClassName("gaugeBttn")[0];
gaugeClick.addEventListener("click", chartFrameSwitch0);
const pieClick = document.getElementsByClassName("pieBttn")[0];
pieClick.addEventListener("click", chartFrameSwitch1);
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.6.0/echarts.min.js"></script>
</head>
<button class="gaugeBttn">
Gauge
</button>
<button class="pieBttn">
Pie
</button>
<div class="chart" style="width: 100%; height: 100vh"></div>