



This example demonstrates angular meters of which the pointers are pivoted at the corners of squares.
The meters in this example are achieved by using various start angles and end angles with 90 degrees angular span between them.
ChartDirector 7.0 (ASP/COM/VB Edition)
Square Angular Meters
Source Code Listing
<%@ language="vbscript" %>
<%
Set cd = CreateObject("ChartDirector.API")
' This script can draw different charts depending on the chartIndex
Sub createChart(viewer, chartIndex)
' The value to display on the meter
value = 4.75
' Create an AugularMeter object of size 110 x 110 pixels, using silver background color with a
' black 2 pixel 3D depressed border.
Set m = cd.AngularMeter(110, 110, cd.silverColor(), &H000000, -2)
' Set meter appearance according to a parameter
If chartIndex = 0 Then
' Set the meter center at bottom left corner (15, 95), with radius 85 pixels. Meter spans
' from 90 - 0 degrees.
Call m.setMeter(15, 95, 85, 90, 0)
' Add a label to the meter centered at (35, 75)
Call m.addText(35, 75, "VDC", "Arial Bold", 12, cd.TextColor, cd.Center)
' Add a text box to show the value at top right corner (103, 7)
Call m.addText(103, 7, m.formatValue(value, "2"), "Arial", 8, &Hffffff, cd.TopRight _
).setBackground(0, 0, -1)
ElseIf chartIndex = 1 Then
' Set the meter center at top left corner (15, 15), with radius 85 pixels. Meter spans from
' 90 - 180 degrees.
Call m.setMeter(15, 15, 85, 90, 180)
' Add a label to the meter centered at (35, 35)
Call m.addText(35, 35, "AMP", "Arial Bold", 12, cd.TextColor, cd.Center)
' Add a text box to show the value at bottom right corner (103, 103)
Call m.addText(103, 103, m.formatValue(value, "2"), "Arial", 8, &Hffffff, cd.BottomRight _
).setBackground(0, 0, -1)
ElseIf chartIndex = 2 Then
' Set the meter center at top right corner (15, 95), with radius 85 pixels. Meter spans from
' 270 - 180 degrees.
Call m.setMeter(95, 15, 85, 270, 180)
' Add a label to the meter centered at (75, 35)
Call m.addText(75, 35, "KW", "Arial Bold", 12, cd.TextColor, cd.Center)
' Add a text box to show the value at bottom left corner (7, 103)
Call m.addText(7, 103, m.formatValue(value, "2"), "Arial", 8, &Hffffff, cd.BottomLeft _
).setBackground(0, 0, -1)
Else
' Set the meter center at bottom right corner (95, 95), with radius 85 pixels. Meter spans
' from 270 - 360 degrees.
Call m.setMeter(95, 95, 85, 270, 360)
' Add a label to the meter centered at (75, 75)
Call m.addText(75, 75, "RPM", "Arial Bold", 12, cd.TextColor, cd.Center)
' Add a text box to show the value at top left corner (7, 7)
Call m.addText(7, 7, m.formatValue(value, "2"), "Arial", 8, &Hffffff, cd.TopLeft _
).setBackground(0, 0, -1)
End If
' Meter scale is 0 - 10, with a major tick every 2 units, and minor tick every 1 unit
Call m.setScale(0, 10, 2, 1)
' Set 0 - 6 as green (99ff99) zone, 6 - 8 as yellow (ffff00) zone, and 8 - 10 as red (ff3333)
' zone
Call m.addZone(0, 6, &H99ff99, &H808080)
Call m.addZone(6, 8, &Hffff00, &H808080)
Call m.addZone(8, 10, &Hff3333, &H808080)
' Add a semi-transparent black (80000000) pointer at the specified value
Call m.addPointer(value, &H80000000)
' Output the chart
Call viewer.setChart(m, cd.SVG)
End Sub
' This example includes 4 charts
Dim viewers(3)
For i = 0 To Ubound(viewers)
Set viewers(i) = cd.WebChartViewer(Request, "chart" & i)
Call createChart(viewers(i), i)
Next
%>
<!DOCTYPE html>
<html>
<head>
<title>Square Angular Meters</title>
<!-- Include ChartDirector Javascript Library to support chart interactions -->
<script type="text/javascript" src="cdjcv.js"></script>
</head>
<body style="margin:5px 0px 0px 5px">
<div style="font:bold 18pt verdana;">
Square Angular Meters
</div>
<hr style="border:solid 1px #000080; background:#000080" />
<div style="font:10pt verdana; margin-bottom:1.5em">
<a href="viewsource.asp?file=<%= Request("SCRIPT_NAME") %>">View Chart Source Code</a>
</div>
<!-- ****** Here are the chart images ****** -->
<%
For i = 0 To Ubound(viewers)
Call Response.Write(viewers(i).renderHTML())
Call Response.Write(" ")
Next
%>
</body>
</html>
Public Sub createChart(viewer As Object, chartIndex As Integer)
Dim cd As New ChartDirector.API
' The value to display on the meter
Dim value As Double
value = 4.75
' Create an AugularMeter object of size 110 x 110 pixels, using silver background color with a
' black 2 pixel 3D depressed border.
Dim m As AngularMeter
Set m = cd.AngularMeter(110, 110, cd.silverColor(), &H000000, -2)
' Set meter appearance according to a parameter
If chartIndex = 0 Then
' Set the meter center at bottom left corner (15, 95), with radius 85 pixels. Meter spans
' from 90 - 0 degrees.
Call m.setMeter(15, 95, 85, 90, 0)
' Add a label to the meter centered at (35, 75)
Call m.addText(35, 75, "VDC", "arialbd.ttf", 12, cd.TextColor, cd.Center)
' Add a text box to show the value at top right corner (103, 7)
Call m.addText(103, 7, m.formatValue(value, "2"), "arial.ttf", 8, &Hffffff, cd.TopRight _
).setBackground(0, 0, -1)
ElseIf chartIndex = 1 Then
' Set the meter center at top left corner (15, 15), with radius 85 pixels. Meter spans from
' 90 - 180 degrees.
Call m.setMeter(15, 15, 85, 90, 180)
' Add a label to the meter centered at (35, 35)
Call m.addText(35, 35, "AMP", "arialbd.ttf", 12, cd.TextColor, cd.Center)
' Add a text box to show the value at bottom right corner (103, 103)
Call m.addText(103, 103, m.formatValue(value, "2"), "arial.ttf", 8, &Hffffff, _
cd.BottomRight).setBackground(0, 0, -1)
ElseIf chartIndex = 2 Then
' Set the meter center at top right corner (15, 95), with radius 85 pixels. Meter spans from
' 270 - 180 degrees.
Call m.setMeter(95, 15, 85, 270, 180)
' Add a label to the meter centered at (75, 35)
Call m.addText(75, 35, "KW", "arialbd.ttf", 12, cd.TextColor, cd.Center)
' Add a text box to show the value at bottom left corner (7, 103)
Call m.addText(7, 103, m.formatValue(value, "2"), "arial.ttf", 8, &Hffffff, cd.BottomLeft _
).setBackground(0, 0, -1)
Else
' Set the meter center at bottom right corner (95, 95), with radius 85 pixels. Meter spans
' from 270 - 360 degrees.
Call m.setMeter(95, 95, 85, 270, 360)
' Add a label to the meter centered at (75, 75)
Call m.addText(75, 75, "RPM", "arialbd.ttf", 12, cd.TextColor, cd.Center)
' Add a text box to show the value at top left corner (7, 7)
Call m.addText(7, 7, m.formatValue(value, "2"), "arial.ttf", 8, &Hffffff, cd.TopLeft _
).setBackground(0, 0, -1)
End If
' Meter scale is 0 - 10, with a major tick every 2 units, and minor tick every 1 unit
Call m.setScale(0, 10, 2, 1)
' Set 0 - 6 as green (99ff99) zone, 6 - 8 as yellow (ffff00) zone, and 8 - 10 as red (ff3333)
' zone
Call m.addZone(0, 6, &H99ff99, &H808080)
Call m.addZone(6, 8, &Hffff00, &H808080)
Call m.addZone(8, 10, &Hff3333, &H808080)
' Add a semi-transparent black (80000000) pointer at the specified value
Call m.addPointer(value, &H80000000)
' Output the chart
Set viewer.Picture = m.makePicture()
End Sub