ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Dynamic rotation of 3d charts using sliders in VBA
Posted by Guillaume on Aug-09-2012 22:16
Hello Peter

I am using chartdirector to chart a 3d dataset in VBA.
Here is the code I use :

Sub cd_test(target As Variant, graphData As Variant)
Dim cd As New ChartDirector.API

Dim strsql As String
Dim rcset As New adodb.Recordset '
Dim dbtable As Variant
Dim dataX As Variant
Dim dataY As Variant
Dim dataZ As Variant

If TypeName(graphData) = "string" Then
    rcset.Open graphData, CurrentProject.Connection
End If

Set dbtable = cd.dbtable(rcset)
dataX = dbtable.getCol(0)
dataY = dbtable.getCol(1)
dataZ = dbtable.getCol(2)

Dim c As SurfaceChart
Set c = cd.SurfaceChart(877, 590)
Call c.addTitle("Nappe de volatilit?", "arialbd.ttf", 10)
Call c.setPlotRegion(350, 280, 360, 360, 270)
Call c.SetData(dataX, dataY, dataZ)
Call c.setColorAxis(645, 270, cd.Left, 200, cd.Right)
Call c.setSurfaceAxisGrid(&HCC000000)
Call c.xAxis().setTitle("Strike", "arialbd.ttf", 10)
Call c.yAxis().setTitle("Maturity", "arialbd.ttf", 10)
Call c.yAxis().setReverse
Call c.zAxis().setTitle("Volatility", "arialbd.ttf", 10)

' Output the chart
Set target.Picture = c.makePicture()

What I would like to do is using 2 MS Forms scrollbars (scrollbarElevation and scrollbarRotation) to dynamically rotate the chart without requerying the data.
Il it possible to have something like this working (obviously, it doesn't work !):

Private Sub scrollbarElevation_Updated(Code As Integer)

Call Me.graphNDV.Object.setViewAngle(Me.scrollbarElevation, Me.scrollbarRotation)

End Sub

Thanks in advance

  Re: Dynamic rotation of 3d charts using sliders in VBA
Posted by Peter Kwan on Aug-10-2012 00:07
Hi Guillaume,

We do this all the time (use some controls to manipulate the view angles) when testing our code. In the simplest case, it is likeL


'Form variables - not local variables inside any subroutine
Dim dataX As Variant
Dim dataY As Variant
Dim dataZ As Variant

'Draw the initial chart
Sub cd_test(target As Variant, graphData As Variant)

Dim cd As New ChartDirector.API

'Read the data
Dim strsql As String
Dim rcset As New adodb.Recordset '
Dim dbtable As Variant

If TypeName(graphData) = "string" Then
    rcset.Open graphData, CurrentProject.Connection
End If

Set dbtable = cd.dbtable(rcset)
dataX = dbtable.getCol(0)
dataY = dbtable.getCol(1)
dataZ = dbtable.getCol(2)

'Draw the chart
Call myChartViewer.UpdateViewPort(True, False)

End


'
' myChartViewer ViewPortChanged event handler
'
Private Sub myChartViewer_ViewPortChanged(needUpdateChart As Boolean, needUpdateImageMap As Boolean)

Dim cd As New ChartDirector.API
Dim c As SurfaceChart
Set c = cd.SurfaceChart(877, 590)
Call c.addTitle("Nappe de volatilit?", "arialbd.ttf", 10)
Call c.setPlotRegion(350, 280, 360, 360, 270)
Call c.setViewAngle(Me.scrollbarElevation.Value, Me.scrollbarRotation.Value)
Call c.SetData(dataX, dataY, dataZ)
Call c.setColorAxis(645, 270, cd.Left, 200, cd.Right)
Call c.setSurfaceAxisGrid(&HCC000000)
Call c.xAxis().setTitle("Strike", "arialbd.ttf", 10)
Call c.yAxis().setTitle("Maturity", "arialbd.ttf", 10)
Call c.yAxis().setReverse
Call c.zAxis().setTitle("Volatility", "arialbd.ttf", 10)

' Output the chart
Set myChartViewer.Picture = c.makePicture()

End Sub


Private Sub scrollbarElevation_Updated(Code As Integer)

'redraw the chart
Call myChartViewer.UpdateViewPort(True, False)

End Sub


Hope this can help.

Regards
Peter Kwan