ChartDirector 7.0 (ASP/COM/VB Edition)
Overlapping Bar Chart
Source Code Listing
<%@ language="vbscript" %>
<%
Set cd = CreateObject("ChartDirector.API")
' The data for the bar chart
data0 = Array(100, 125, 156, 147, 87, 124, 178, 109, 140, 106, 192, 122)
data1 = Array(122, 156, 179, 211, 198, 177, 160, 220, 190, 188, 220, 270)
data2 = Array(167, 190, 213, 267, 250, 320, 212, 199, 245, 267, 240, 310)
labels = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec")
' Create a XYChart object of size 580 x 280 pixels
Set c = cd.XYChart(580, 280)
' Add a title to the chart using 14pt Arial Bold Italic font
Call c.addTitle("Product Revenue For Last 3 Years", "Arial Bold Italic", 14)
' Set the plot area at (50, 50) and of size 500 x 200. Use two alternative background colors (f8f8f8
' and ffffff)
Call c.setPlotArea(50, 50, 500, 200, &Hf8f8f8, &Hffffff)
' Add a legend box at (50, 25) using horizontal layout. Use 8pt Arial as font, with transparent
' background.
Call c.addLegend(50, 25, False, "Arial", 8).setBackground(cd.Transparent)
' Set the x axis labels
Call c.xAxis().setLabels(labels)
' Draw the ticks between label positions (instead of at label positions)
Call c.xAxis().setTickOffset(0.5)
' Add a multi-bar layer with 3 data sets
Set layer = c.addBarLayer2(cd.Side)
Call layer.addDataSet(data0, &Hff8080, "Year 2003")
Call layer.addDataSet(data1, &H80ff80, "Year 2004")
Call layer.addDataSet(data2, &H8080ff, "Year 2005")
' Set 50% overlap between bars
Call layer.setOverlapRatio(0.5)
' Add a title to the y-axis
Call c.yAxis().setTitle("Revenue (USD in millions)")
' Output the chart
Set viewer = cd.WebChartViewer(Request, "chart1")
Call viewer.setChart(c, cd.SVG)
' Include tool tip for the chart
viewer.ImageMap = c.getHTMLImageMap("", "", _
"title='{xLabel} Revenue on {dataSetName}: {value} millions'")
%>
<!DOCTYPE html>
<html>
<head>
<title>Overlapping Bar Chart</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;">
Overlapping Bar Chart
</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 data for the bar chart
Dim data0()
data0 = Array(100, 125, 156, 147, 87, 124, 178, 109, 140, 106, 192, 122)
Dim data1()
data1 = Array(122, 156, 179, 211, 198, 177, 160, 220, 190, 188, 220, 270)
Dim data2()
data2 = Array(167, 190, 213, 267, 250, 320, 212, 199, 245, 267, 240, 310)
Dim labels()
labels = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", _
"Dec")
' Create a XYChart object of size 580 x 280 pixels
Dim c As XYChart
Set c = cd.XYChart(580, 280)
' Add a title to the chart using 14pt Arial Bold Italic font
Call c.addTitle("Product Revenue For Last 3 Years", "arialbi.ttf", 14)
' Set the plot area at (50, 50) and of size 500 x 200. Use two alternative background colors
' (f8f8f8 and ffffff)
Call c.setPlotArea(50, 50, 500, 200, &Hf8f8f8, &Hffffff)
' Add a legend box at (50, 25) using horizontal layout. Use 8pt Arial as font, with transparent
' background.
Call c.addLegend(50, 25, False, "arial.ttf", 8).setBackground(cd.Transparent)
' Set the x axis labels
Call c.xAxis().setLabels(labels)
' Draw the ticks between label positions (instead of at label positions)
Call c.xAxis().setTickOffset(0.5)
' Add a multi-bar layer with 3 data sets
Dim layer As BarLayer
Set layer = c.addBarLayer2(cd.Side)
Call layer.addDataSet(data0, &Hff8080, "Year 2003")
Call layer.addDataSet(data1, &H80ff80, "Year 2004")
Call layer.addDataSet(data2, &H8080ff, "Year 2005")
' Set 50% overlap between bars
Call layer.setOverlapRatio(0.5)
' Add a title to the y-axis
Call c.yAxis().setTitle("Revenue (USD in millions)")
' Output the chart
Set viewer.Picture = c.makePicture()
'include tool tip for the chart
viewer.ImageMap = c.getHTMLImageMap("clickable", "", _
"title='{xLabel} Revenue on {dataSetName}: {value} millions'")
End Sub