ChartDirector 7.0 (ASP/COM/VB Edition)

Pattern Area Chart




This example demonstrates using a pattern for filling the area in an area chart, together with a number of chart formatting features.

Source Code Listing

[Web Version (in ASP)] aspdemo\patternarea.asp
<%@ language="vbscript" %> <% Set cd = CreateObject("ChartDirector.API") ' The data for the area chart data = Array(3.0, 2.8, 4.0, 5.5, 7.5, 6.8, 5.4, 6.0, 5.0, 6.2, 7.5, 6.5, 7.5, 8.1, 6.0, 5.5, 5.3, _ 3.5, 5.0, 6.6, 5.6, 4.8, 5.2, 6.5, 6.2) ' The labels for the area chart labels = Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", _ "15", "16", "17", "18", "19", "20", "21", "22", "23", "24") ' Create a XYChart object of size 300 x 180 pixels. Set the background to pale yellow (0xffffa0) ' with a black border (0x0) Set c = cd.XYChart(300, 180, &Hffffa0, &H000000) ' Set the plotarea at (45, 35) and of size 240 x 120 pixels. Set the background to white (0xffffff). ' Set both horizontal and vertical grid lines to black (&H0&) dotted lines (pattern code 0x0103) Call c.setPlotArea(45, 35, 240, 120, &Hffffff, -1, -1, c.dashLineColor(&H000000, &H000103), _ c.dashLineColor(&H000000, &H000103)) ' Add a title to the chart using 10pt Arial Bold font. Use a 1 x 2 bitmap pattern as the background. ' Set the border to black (0x0). Call c.addTitle("Snow Percipitation (Dec 12)", "Arial Bold", 10).setBackground(c.patternColor( _ Array(&Hb0b0f0, &He0e0ff), 2), &H000000) ' Add a title to the y axis Call c.yAxis().setTitle("mm per hour") ' Set the labels on the x axis. Call c.xAxis().setLabels(labels) ' Display 1 out of 3 labels on the x-axis. Call c.xAxis().setLabelStep(3) ' Add an area layer to the chart Set layer = c.addAreaLayer() ' Load a snow pattern from an external file "snow.png". snowPattern = c.patternColor2(Server.MapPath("snow.png")) ' Add a data set to the area layer using the snow pattern as the fill color. Use deep blue ' (0x0000ff) as the area border line color (&H0000ff&) Call layer.addDataSet(data).setDataColor(snowPattern, &H0000ff) ' Set the line width to 2 pixels to highlight the line Call layer.setLineWidth(2) ' 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}:00 - {value} mm/hour'") %> <!DOCTYPE html> <html> <head> <title>Pattern Area 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;"> Pattern Area 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>

[Windows Version (in Visual Basic)] vbdemo\patternarea.cls
Public Sub createChart(viewer As Object, chartIndex As Integer) Dim cd As New ChartDirector.API ' The data for the area chart Dim data() data = Array(3.0, 2.8, 4.0, 5.5, 7.5, 6.8, 5.4, 6.0, 5.0, 6.2, 7.5, 6.5, 7.5, 8.1, 6.0, 5.5, _ 5.3, 3.5, 5.0, 6.6, 5.6, 4.8, 5.2, 6.5, 6.2) ' The labels for the area chart Dim labels() labels = Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", _ "15", "16", "17", "18", "19", "20", "21", "22", "23", "24") ' Create a XYChart object of size 300 x 180 pixels. Set the background to pale yellow (0xffffa0) ' with a black border (0x0) Dim c As XYChart Set c = cd.XYChart(300, 180, &Hffffa0, &H000000) ' Set the plotarea at (45, 35) and of size 240 x 120 pixels. Set the background to white ' (0xffffff). Set both horizontal and vertical grid lines to black (&H0&) dotted lines (pattern ' code 0x0103) Call c.setPlotArea(45, 35, 240, 120, &Hffffff, -1, -1, c.dashLineColor(&H000000, &H000103), _ c.dashLineColor(&H000000, &H000103)) ' Add a title to the chart using 10pt Arial Bold font. Use a 1 x 2 bitmap pattern as the ' background. Set the border to black (0x0). Call c.addTitle("Snow Percipitation (Dec 12)", "arialbd.ttf", 10).setBackground( _ c.patternColor(Array(&Hb0b0f0, &He0e0ff), 2), &H000000) ' Add a title to the y axis Call c.yAxis().setTitle("mm per hour") ' Set the labels on the x axis. Call c.xAxis().setLabels(labels) ' Display 1 out of 3 labels on the x-axis. Call c.xAxis().setLabelStep(3) ' Add an area layer to the chart Dim layer As AreaLayer Set layer = c.addAreaLayer() ' Load a snow pattern from an external file "snow.png". Dim snowPattern As Long snowPattern = c.patternColor2("snow.png") ' Add a data set to the area layer using the snow pattern as the fill color. Use deep blue ' (0x0000ff) as the area border line color (&H0000ff&) Call layer.addDataSet(data).setDataColor(snowPattern, &H0000ff) ' Set the line width to 2 pixels to highlight the line Call layer.setLineWidth(2) ' Output the chart Set viewer.Picture = c.makePicture() 'include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{xLabel}:00 - {value} mm/hour'") End Sub