javascript - In the timeline context, universalTransition and multiple timelines don't work - Stack Overflow

I have a code that has two problems:(1) universalTransition doesn't work in the timeline context.

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)?

Share Improve this question edited Mar 6 at 21:54 neves asked Mar 6 at 15:24 nevesneves 8162 gold badges12 silver badges41 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

ECharts 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744966405a4603706.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信