为条形图设置动画
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为条形图设置动画相关的知识,希望对你有一定的参考价值。
import com.greensock.*; import com.greensock.easing.*; // --------------------------- // Bar Char graph animation // --------------------------- // Enter number of bars var bars:Number=2; var animationDirection:String="vertical";// horizontal var graphLabels:Boolean=true;// Are there any labels above or on bars? // Trigger this function to start animation setUp(); // Fade in axis axis_mc.alpha=0; TweenMax.to(axis_mc, 1, {alpha:1}); // Test to see direction and set bars ready to animate function setUp():void{ switch (animationDirection) { case "vertical" : for (var i:Number = 1; i<=bars; i++) { this["bar"+i].y = this["bar"+i].y + this["bar"+i].height; } break; case "horizontal" : for (var j:Number = 1; j<=bars; j++) { this["bar"+j].x = this["bar"+j].x - this["bar"+j].width; } break; } if(graphLabels) hideLabels(); TweenMax.delayedCall(1,animateBars); } // Test to see direction and animate bars function animateBars():void{ switch (animationDirection) { case "vertical" : for (var i:Number = 1; i<=bars; i++) { TweenMax.to(this["bar"+i], 1, {y:this["bar"+i].y-this["bar"+i].height, delay:0.2*i, ease:Circ.easeOut}); } break; case "horizontal" : for (var j:Number = 1; j<=bars; j++) { TweenMax.to(this["bar"+j], 1, {x:this["bar"+j].x+this["bar"+j].width, delay:0.2*j, ease:Circ.easeOut}); } break; } } function hideLabels(){ for(var i:Number = 1; i<=bars ; i++) { this["barLabel"+i].alpha = 0; } TweenMax.delayedCall(2,animateLabels); } function animateLabels(){ for(var i:Number = 1; i<=bars ; i++) { TweenMax.to(this["barLabel"+i],0.5,{alpha:1, delay:0.2*i}); } } // --------------------------- // Bar Char graph animation // ---------------------------
以上是关于为条形图设置动画的主要内容,如果未能解决你的问题,请参考以下文章
R语言ggplot2可视化改变柱状图(条形图)的填充色实战:默认的颜色为灰色改变柱状图(条形图)的填充色设置每个柱子(条形)使用不同的色彩
R语言gganimate包创建可视化gif动图:ggplot2可视化静态条形图(bar plot)gganimate包创建动态条形图(bar plot)动画基于transition_time函数