Tutorial: Rotation Example (Dundas Chart Server Control 1.0)

Dundas

Tutorial: Rotation Example


In order to rotate a chart you must let the chart instance know what the rotational angles were after the last rotation operation (defaults are used when the first rotation occurs) before calling the Rotate method. This means that you must preserve state information (session-level variables, hidden inputboxes, etc.) between Chart object creation/deletion.

To set the initial rotation angles use your preserved state information and set the AngleX, AngleY and AngleZ properties. Once you have set the previous rotation angles you can then call the Rotate method to rotate the chart. Before the chart object is destroyed MAKE SURE that you store the new rotation angles (to be used for the next rotation operation).  this can be done using session variables, hidden input boxes, etc.

Refer to the sample source code below for further clarification.

Example

If you do not know how to create a template using the Template Creator then click here for instructions on how to do so.  This tutorial DOES NOT cover how to make your pie chart templates, it assumes you already have a template ready to be loaded.

Scenario - We will allow the user to rotate a pie chart clockwise.
- The amount of rotation will be hard-coded to 20 degrees.
- State information concerning the last displayed position
of the chart will be preserved by using session-level variables.
- Main.asp will display the chart, while MakeJpeg.asp will actually
create the chart jpeg.

Main.asp
<Html>

<Head>

</Head>

<Body><Center>
<IMG height="300" src="MakeJpeg.asp" width="300"></Center>
<form action="Main.asp" method="post" id="form1" name="form1">
<input type="submit" name="cmdRotate" id="cmdRotate" value="Rotate">
</form>
</Body>
</Html>

MakeJpeg.asp
<%
'disable caching so that image is always retrieved from server

Response.Buffer = True
Response.CacheControl = "Private"
Response.Expires = -1000

'create an instance of the control
Set
objChart = Server.CreateObject("Dundas.ChartServer")

'set required directory properties
objChart.DirTexture = "c:\dschart\dschart_local\Textures"
objChart.DirTemplate = "c:\dschart\dschart_local\Templates"

'load a pie chart template, made with the Template Creator
ret = objChart.LoadTemplate("Rotation.cuc")

'now add some data to the pie chart
ret = objChart.AddData(900)
ret = objChart.AddData(1900)
ret = objChart.AddData(200)
ret = objChart.AddData(400)

'if one rotation operation has already occurred then we need to
' let the chart know its previous location

If
Session("AngleX") <> "" Then objChart.AngleX = Session("AngleX")
If
Session("AngleY") <> "" Then objChart.AngleY = Session("AngleY")
If
Session("AngleZ") <> "" Then objChart.AngleZ = Session("AngleZ")

'now rotate the chart 20 degrees clockwise (around the window's z-axis)
ret = objChart.Rotate(-20,2)

'now set session-level variables so we can set the chart object's
' previous location the next time we rotate the chart

Session("AngleX") = objChart.AngleX
Session("AngleY") = objChart.AngleY
Session("AngleZ") = objChart.AngleZ

'now output the pie chart jpeg
ret = objChart.SendJpeg(300,300)
'lets check the return value (useful for debugging)

If
ret <> 0 Then
strErrorCode = objChart.GetErrorText(ret)
End
If

'release resources
Set
objChart = Nothing
%>

See Also: Tutorial: Creating a Basic Pie Chart | Tutorial: Drilldown and Selection of Data Elements