Home >Web Front-end >JS Tutorial >How to add animation effects in ECharts
ECharts is an open source visualization chart library based on JavaScript. It provides a rich range of chart types and interactive functions and is widely used in the field of data visualization. Compared with static charts, dynamic charts are more vivid and intuitive and can better show changes and trends in data. Therefore, adding animation effects in ECharts can enhance the attractiveness and readability of charts, while also being more in line with the aesthetic needs of modern users.
This article will introduce how to add animation effects in ECharts and provide specific code examples for reference.
var myChart = echarts.init(document.getElementById('main'), null, {animation: true}); //或者 var option = { animation: { duration: 2000, //动画持续时间,单位为毫秒 easing: 'elasticOut' //缓动函数类型 }, //其他配置项... }; var myChart = echarts.init(document.getElementById('main'), null, option);
option = { xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], animation: true, //启用x轴的动画效果 axisLabel: { interval: 0 } }, yAxis: { type: 'value', animation: { duration: 2000, //y轴的动画持续时间,单位为毫秒 easing: 'bounceOut' //缓动函数类型 } }, series: [{ name: 'sales', type: 'bar', data: [120, 200, 150, 80, 70, 110, 130], animationDelay: function (idx) { //启用条形图的动画效果 return idx * 500; } }] };
myChart.setOption(option);
The following is a complete ECharts animation sample code:
var myChart = echarts.init(document.getElementById('main'), null, {animation: true}); var option = { xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], animation: true, axisLabel: { interval: 0 } }, yAxis: { type: 'value', animation: { duration: 2000, easing: 'bounceOut' } }, series: [{ name: 'sales', type: 'bar', data: [120, 200, 150, 80, 70, 110, 130], animationDelay: function (idx) { return idx * 500; } }] }; myChart.setOption(option);
Through the above example, we can easily add various animation effects in ECharts and turn the data visualization chart into More vivid and easier to understand. At the same time, we also need to pay attention to the rationality and practicality of animation effects to avoid being overly cool and affecting the user experience.
The above is the detailed content of How to add animation effects in ECharts. For more information, please follow other related articles on the PHP Chinese website!