admin管理员组文章数量:1406052
I have a code that has two problems:
(1) universalTransition doesn't work in the timeline context.
In each data
property I have configured the groupId
to work with its corresponding graph, but the transition does not occur in the context of timeline
. Outside of timeline
, the transition occurs normally.
(2) timeline: [{...}, {...}]
doesn't seem to work (only the first object has an effect, as if there were an interference).
I set up the timeline with this format:
timeline: [
{...},
{...}
]
But this creates a problem, because the second timeline has no effect, even when you change the axisType
, for example.
Full code:
HTML
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=".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>
I have a code that has two problems:
(1) universalTransition doesn't work in the timeline context.
In each data
property I have configured the groupId
to work with its corresponding graph, but the transition does not occur in the context of timeline
. Outside of timeline
, the transition occurs normally.
(2) timeline: [{...}, {...}]
doesn't seem to work (only the first object has an effect, as if there were an interference).
I set up the timeline with this format:
timeline: [
{...},
{...}
]
But this creates a problem, because the second timeline has no effect, even when you change the axisType
, for example.
Full code:
HTML
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/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>
I could solve this by using several instances, but I only want to keep one: chartUse
.
EDIT
According to this answer, echarts only accepts a single timeline:
timeline: {...}
not:
timeline: [{...}, {...}]
So the question now lies in the universalTransition
between charts that are not part of the timeline, i.e. gauge and pie charts (stuckSeries
).The charts within the timeline use universalTransition
normally, but how can it be applied to fixed charts as well, while maintaining the same instance (chartUse
)?
1 Answer
Reset to default 0ECharts only supports one timeline
object, not an array. Instead of:
timeline: [{...}, {...}]
Use:
timeline: {...}
For universalTransition
to work with fixed charts (gauge ↔ pie), use setOption with replaceMerge: ["series"]
to transition between different chart types while keeping the same instance (chartUse
).
Modify your chartFrameSwitch1()
function:
const option = {
series: series0
};
chartUse.setOption(option, { replaceMerge: ["series"] });
This ensures universalTransition
applies to charts outside the timeline.
本文标签:
版权声明:本文标题:javascript - In the timeline context, universalTransition and multiple timelines don't work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744966405a2634973.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论