ChartDirector 6.0 (ASP/COM/VB Edition)

Simple Rose Chart




This example demonstrates how to create a rose chart.

A rose chart is basically a polar chart with sectors of variable radius. This can be achieved by creating a PolarChart object as the graph paper, and adding sector zones on it using AngularAxis.addZone.

To enable auto-scale of the axis, in this example, we also add the radius data to a transparent line layer using PolarChart.addLineLayer. The line layer has no visible effect, but it causes the radial axis to auto-scale so that it covers the radius data.

Source Code Listing

[Web Version (in ASP)] aspdemo\rose.asp
<%@ language="vbscript" %>
<%
Set cd = CreateObject("ChartDirector.API")

' Data for the chart
data = Array(9.4, 1.8, 2.1, 2.3, 3.5, 7.7, 8.8, 6.1, 5.0, 3.1, 6.0, 4.3, 5.1, 2.6, 1.5, 2.2, 5.1, _
    4.3, 4.0, 9.0, 1.7, 8.8, 9.9, 9.5)
angles = Array(0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, _
    270, 285, 300, 315, 330, 345)

' Create a PolarChart object of size 460 x 460 pixels, with a silver background and a 1 pixel 3D
' border
Set c = cd.PolarChart(460, 460, cd.silverColor(), &H000000, 1)

' Add a title to the chart at the top left corner using 15pt Arial Bold Italic font. Use white text
' on deep blue background.
Call c.addTitle("Polar Vector Chart Demonstration", "arialbi.ttf", 15, &Hffffff).setBackground( _
    &H000080)

' Set plot area center at (230, 240) with radius 180 pixels and white background
Call c.setPlotArea(230, 240, 180, &Hffffff)

' Set the grid style to circular grid
Call c.setGridStyle(False)

' Set angular axis as 0 - 360, with a spoke every 30 units
Call c.angularAxis().setLinearScale(0, 360, 30)

' Add sectors to the chart as sector zones
For i = 0 To UBound(data)
    Call c.angularAxis().addZone(angles(i), angles(i) + 15, 0, data(i), &H33ff33, &H008000)
Next

' Add an Transparent invisible layer to ensure the axis is auto-scaled using the data
Call c.addLineLayer(data, cd.Transparent)

' Output the chart
Response.ContentType = "image/png"
Response.BinaryWrite c.makeChart2(cd.PNG)
Response.End
%>

[Windows Version (in Visual Basic)] vbdemo\rose.cls
Public Sub createChart(viewer As Object, chartIndex As Integer)

    Dim cd As New ChartDirector.API

    ' Data for the chart
    Dim data()
    data = Array(9.4, 1.8, 2.1, 2.3, 3.5, 7.7, 8.8, 6.1, 5.0, 3.1, 6.0, 4.3, 5.1, 2.6, 1.5, 2.2, _
        5.1, 4.3, 4.0, 9.0, 1.7, 8.8, 9.9, 9.5)
    Dim angles()
    angles = Array(0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, _
        255, 270, 285, 300, 315, 330, 345)

    ' Create a PolarChart object of size 460 x 460 pixels, with a silver background and a 1 pixel 3D
    ' border
    Dim c As PolarChart
    Set c = cd.PolarChart(460, 460, cd.silverColor(), &H000000, 1)

    ' Add a title to the chart at the top left corner using 15pt Arial Bold Italic font. Use white
    ' text on deep blue background.
    Call c.addTitle("Polar Vector Chart Demonstration", "arialbi.ttf", 15, &Hffffff _
        ).setBackground(&H000080)

    ' Set plot area center at (230, 240) with radius 180 pixels and white background
    Call c.setPlotArea(230, 240, 180, &Hffffff)

    ' Set the grid style to circular grid
    Call c.setGridStyle(False)

    ' Set angular axis as 0 - 360, with a spoke every 30 units
    Call c.angularAxis().setLinearScale(0, 360, 30)

    ' Add sectors to the chart as sector zones
    Dim i As Long
    For i = 0 To UBound(data)
        Call c.angularAxis().addZone(angles(i), angles(i) + 15, 0, data(i), &H33ff33, &H008000)
    Next

    ' Add an Transparent invisible layer to ensure the axis is auto-scaled using the data
    Call c.addLineLayer(data, cd.Transparent)

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

End Sub