ChartDirector 7.0 (ASP/COM/VB Edition)
Linear Zone Meter
Source Code Listing
<%@ language="vbscript" %>
<%
Set cd = CreateObject("ChartDirector.API")
' The value to display on the meter
value = 85
' Create an LinearMeter object of size 210 x 45 pixels, using silver background with a 2 pixel black
' 3D depressed border.
Set m = cd.LinearMeter(210, 45, cd.silverColor(), 0, -2)
' Set the scale region top-left corner at (5, 5), with size of 200 x 20 pixels. The scale labels are
' located on the bottom (implies horizontal meter)
Call m.setMeter(5, 5, 200, 20, cd.Bottom)
' Set meter scale from 0 - 100
Call m.setScale(0, 100)
' Add a title at the bottom of the meter with a 1 pixel raised 3D border
Call m.addTitle2(cd.Bottom, "Battery Level", "Arial Bold", 8).setBackground(cd.Transparent, -1, 1)
' Set 3 zones of different colors to represent Good/Weak/Bad data ranges
Call m.addZone(50, 100, &H99ff99, "Good")
Call m.addZone(20, 50, &Hffff66, "Weak")
Call m.addZone(0, 20, &Hffcccc, "Bad")
' Add empty labels (just need the ticks) at 0/20/50/80 as separators for zones
Call m.addLabel(0, " ")
Call m.addLabel(20, " ")
Call m.addLabel(50, " ")
Call m.addLabel(100, " ")
' Add a semi-transparent blue (800000ff) pointer at the specified value, using triangular pointer
' shape
Call m.addPointer(value, &H800000ff).setShape(cd.TriangularPointer)
' Output the chart
Set viewer = cd.WebChartViewer(Request, "chart1")
Call viewer.setChart(m, cd.SVG)
%>
<!DOCTYPE html>
<html>
<head>
<title>Linear Zone Meter</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;">
Linear Zone Meter
</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 is the chart image ****** -->
<%= viewer.renderHTML() %>
</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 = 85
' Create an LinearMeter object of size 210 x 45 pixels, using silver background with a 2 pixel
' black 3D depressed border.
Dim m As LinearMeter
Set m = cd.LinearMeter(210, 45, cd.silverColor(), 0, -2)
' Set the scale region top-left corner at (5, 5), with size of 200 x 20 pixels. The scale labels
' are located on the bottom (implies horizontal meter)
Call m.setMeter(5, 5, 200, 20, cd.Bottom)
' Set meter scale from 0 - 100
Call m.setScale(0, 100)
' Add a title at the bottom of the meter with a 1 pixel raised 3D border
Call m.addTitle2(cd.Bottom, "Battery Level", "arialbd.ttf", 8).setBackground(cd.Transparent, _
-1, 1)
' Set 3 zones of different colors to represent Good/Weak/Bad data ranges
Call m.addZone(50, 100, &H99ff99, "Good")
Call m.addZone(20, 50, &Hffff66, "Weak")
Call m.addZone(0, 20, &Hffcccc, "Bad")
' Add empty labels (just need the ticks) at 0/20/50/80 as separators for zones
Call m.addLabel(0, " ")
Call m.addLabel(20, " ")
Call m.addLabel(50, " ")
Call m.addLabel(100, " ")
' Add a semi-transparent blue (800000ff) pointer at the specified value, using triangular
' pointer shape
Call m.addPointer(value, &H800000ff).setShape(cd.TriangularPointer)
' Output the chart
Set viewer.Picture = m.makePicture()
End Sub