Microsoft Office Tutorials and References
In Depth Information
Animating Charts
A relatively simple macro makes the chart scroll. The button in the worksheet executes the
following macro that scrolls (or stops scrolling) the chart:
Public AnimationInProgress As Boolean
Sub AnimateChart()
Dim StartVal As Long, r As Long
If AnimationInProgress Then
AnimationInProgress = False
End
End If
AnimationInProgress = True
StartVal = Range(“StartDay”)
For r = StartVal To 5219 - Range(“NumDays”) _
Step Range(“Increment”)
Range(“StartDay”) = r
DoEvents
Next r
AnimationInProgress = False
End Sub
The AnimateChart procedure uses a public variable ( AnimationInProgress ) to keep track
of the animation status. The animation results from a loop that changes the value in the
StartDay cell. Because the two chart series use this value, the chart is continually updated with
a new starting value. The Scroll Increment setting determines how quickly the chart scrolls.
To stop the animation, I use an End statement rather than an Exit Sub statement. For some
reason, Exit Sub doesn’t work reliably and may even crash Excel.
Creating a hypocycloid chart
Even if you hated your high school trigonometry class, you’ll probably like the example in this
section — which relies heavily on trigonometric functions. The workbook shown in Figure 18-23
contains an XY chart that displays a nearly infinite number of dazzling hypocycloid curves. A
hypocycloid curve is the path formed by a point on a circle that rolls inside of another circle. This,
as you may recall from your childhood, is the same technique used in Hasbro’s popular
Spirograph toy.
This workbook is available on the companion CD-ROM. The filename is hypocycloid -
animate.xlsm .
The chart is an XY chart, with everything hidden except the data series. The X and Y data are
generated by using formulas stored in columns A and B. The scroll bar controls at the top let you
adjust the three parameters that determine the look of the chart. In addition, clicking the Random
button generates random values for the three parameters.
 
Search JabSto ::




Custom Search