Tutorial: Creating a Basic Pie Chart (Dundas Pie Chart Server 1.0)

Dundas

Tutorial: Creating a Basic Pie Chart

To use this control in a web site you will need to use two (2) web pages. One ASP page (let's call it the secondary page) creates an instance of the ASP Pie Chart control, loads a template, adds the specified data and then calls SendJPEG to send the data to the client. The other page (lets call it the main page) retrieves the pie chart image by embedding the secondary ASP page in an <IMG> tag or <A> tag with the SRC attribute set to the secondary page. The main page can be either an html or ASP file.

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.

IMPORTANT: the Intel compression library (ijl15.dll) MUST be located in either your system directory or at the same directory level as both the chart server control and the Template Creator, otherwise both the control and the Creator will not function correctly.

Click here for instructions on how to debug the Pie Chart Server.  For further information concerning debugging, as well as FAQs, and troubleshooting go to our developer site.

To output a pie chart jpeg perform the following actions in their specified order:

  1. Create the main page (ASP or html) and embed the secondary page (ASP) into it with either an <IMG> tag or <A> tag.

  2. Create the secondary page (ASP) and perform the following actions in their indicated order:

  • The Pie Chart Server will throw an exception if an error occurs, so enable error handling with an "On Error Resume Next" statement.

  • Create an ASPPieChart object by using CreateObject (e.g. CreateObject("Dundas.PieChartServer.1")).

  • Set the directory properties of the control which specify working directories for different aspects of chart activity. These properties are DirTemplate and DirTexture, and deal with the directories used to store templates and textures, respectively.

  • Load a template via the LoadTemplate method.

  • Set the properties of the pie chart (e.g. exploded pieces, collected element properties, etc.)

  • Add pie chart data with the AddData method.

  • Send the resulting jpeg directly to a client with the SendJPEG method or alternatively you can save the jpeg to disk with CreateJPEGFile and then present the image to a user with a standard <IMG> tag.

  • If you want to generate another Jpeg using the same template then repeat Steps 4 to 6. If you want to create another jpeg with a different template repeat steps 1 to 6.

  • Destroy the Pie Chart object by setting it to Nothing (e.g. Set objPieChart = Nothing).

  • MAKE SURE that there is no html code in this ASP page which outputs the jpeg.

The ProgID of the control is: Dundas.PieChartServer.2

Example

'Displays a pie chart in an html page

'lets make the main page, and call it Main.htm <Html>
<Body>
<IMG SRC="MakeJpeg.asp">
</Body></Html>

'now make the secondary page which outputs the jpeg
'let's call it MakeJpeg.asp

<%
'make sure browser never uses cached copy of jpeg

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

'enable error handling, since an exception will be thrown if an error occurs. To debug this page
' disable the Resume Next statement and load this page directly into your browser, and observe
' the raised exception.

On Error Resume Next

'retrieve the physical directory where ASP pages are located
strPath = Server.MapPath(".")

'create an instance of the control
Set
objPieChart = Server.CreateObject("Dundas.PieChartServer.1")

'set the Template directory of the control
objPieChart.DirTemplate = strPath & "\Templates\"

'set the Textures directory of the control
objPieChart.DirTexture = strPath & "\Textures\"

'load any template (made with the Template Editor)
ret = objPieChart.LoadTemplate("Textures.cuc")
'check for an error. If the method call is not successful then the
' returned error code will not be zero (0) and in addition an exception will be thrown.
'See the "Debugging" section at the bottom of this page for information on how to debug your pie charts.

If
ret <> 0 Then
Response.Write objPieChart.GetErrorText(ret)
End If

'add 3 slices to the pie chart and specify values (sizes), slice labels and legend labels
ret = objPieChart.AddData(25, "Label1","Slice1")
ret = objPieChart.AddData(25, "Label2","Slice2")
ret = objPieChart.AddData(25, "Label3","Slice3")
'check for an error. If method not successful then output the

' corresponding error string. See the "Debugging" section below for

' more details concerning debugging the pie chart server

If
ret <> 0 Then
Response.Write objPieChart.GetErrorText(ret)
End If

'output graphics, specifying the width and height of the image in pixels
ret = objPieChart.SendJPEG(450,350)
If
ret <> 0 Then
Response.Write objPieChart.GetErrorText(ret)
End If

'destroy AspPieChart object
Set
objPieChart = Nothing
%>

Notice that there is NO HTML CODE in this page which outputs the jpeg!

 
Debugging the Pie Chart Server

If an error occurs then an exception will be raised and the returned error code will not be zero (0). Since an exception will be raised MAKE SURE that the page which outputs the jpeg has an "On Error Resume Next" statement.

To debug the Pie Chart Server control you should load the page which contains the "SendJPEG" call directly into your browser, and you can then use either the control's GetErrorText method (explained in detail below) or you can merely examine the exception thrown by the control (make sure the "On Error Resume Next" statement is disabled).

If an error occurs and a pie chart image is not produced you can also retrieve a relevant error string by loading the page which produces the JPEG directly into your browser and observing the error string generated by the control's GetErrorText method. For example, in the preceding sample code you could load the MakeJpeg.asp page directly into your browser and then see what GetErrorText returns.

Note that this method of retrieving relevant error strings will only work if the page that produces the JPEG image contains NO html code (e.g. the page only contains server-side ASP code).

See Also: Tutorial: Drilldown and Selection of Data Elements | Tutorial: Rotation