ChartDirector 7.0 (ASP/COM/VB Edition)

Exploded Pie Chart




This example demonstrates a pie chart with all sectors exploded. It also demonstrates many effects, such as gradient color background, rounded frame, soft drop shadow, custom sector colors, sector gradient shading, thick sector border, and using CDML and Parameter Substitution and Formatting to format sector labels.

Source Code Listing

[Web Version (in ASP)] aspdemo\explodedpie.asp
<%@ language="vbscript" %> <% Set cd = CreateObject("ChartDirector.API") ' The data for the pie chart data = Array(21, 18, 15, 12, 8, 24) ' The labels for the pie chart labels = Array("Labor", "Licenses", "Taxes", "Legal", "Facilities", "Production") ' The colors to use for the sectors colors = Array(&H66aaee, &Heebb22, &Hbbbbbb, &H8844ff, &Hdd2222, &H009900) ' Create a PieChart object of size 600 x 360 pixels. Set c = cd.PieChart(600, 360) ' Use the white on black palette, which means the default text and line colors are white Call c.setColors(cd.whiteOnBlackPalette) ' Use a vertical gradient color from deep blue (000066) to blue (0000cc) as background. Use rounded ' corners of 20 pixels radius. Enable soft drop shadow. Call c.setBackground(c.linearGradientColor(0, 0, 0, c.getHeight(), &H000066, &H0000cc)) Call c.setRoundedFrame(&Hffffff, 20) Call c.setDropShadow() ' Add a title using 18pt Times New Roman Bold Italic font. Add 16 pixels top margin to the title. Call c.addTitle("Exploded Pie Chart Demonstration", "Times New Roman Bold Italic", 18).setMargin2( _ 0, 0, 16, 0) ' Set the center of the pie at (300, 195) and the radius to 110 pixels Call c.setPieSize(300, 195, 110) ' Set the pie data and the pie labels Call c.setData(data, labels) ' Set the sector colors Call c.setColors2(cd.DataColor, colors) ' Use local gradient shading for the sectors, with 5 pixels wide semi-transparent white (bbffffff) ' borders Call c.setSectorStyle(cd.LocalGradientShading, &Hbbffffff, 5) ' Use the side label layout method Call c.setLabelLayout(cd.SideLayout) ' Use 10pt Arial Bold as the default label font. Set the label box background color the same as the ' sector color. Use soft lighting effect with light direction from right. Use 8 pixels rounded ' corners. Set t = c.setLabelStyle("Arial Bold", 10, &H000000) Call t.setBackground(cd.SameAsMainColor, cd.Transparent, cd.softLighting(cd.Right, 0)) Call t.setRoundedCorners(8) ' Set the sector label format. The label is centered in a 110 pixels wide bounding box. It consists ' of two lines. The first line is the sector name. The second line shows the data value and ' percentage. Call c.setLabelFormat( _ "<*block,halign=center,width=110*>{label}<*br*><*font=Arial,size=8*>US$ {value}M " & _ "({percent}%)<*/*>") ' Explode all sectors 10 pixels from the center Call c.setExplode(-1, 10) ' 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='{label}: US${value}M ({percent}%)'") %> <!DOCTYPE html> <html> <head> <title>Exploded Pie 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;"> Exploded Pie 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\explodedpie.cls
Public Sub createChart(viewer As Object, chartIndex As Integer) Dim cd As New ChartDirector.API ' The data for the pie chart Dim data() data = Array(21, 18, 15, 12, 8, 24) ' The labels for the pie chart Dim labels() labels = Array("Labor", "Licenses", "Taxes", "Legal", "Facilities", "Production") ' The colors to use for the sectors Dim colors() colors = Array(&H66aaee, &Heebb22, &Hbbbbbb, &H8844ff, &Hdd2222, &H009900) ' Create a PieChart object of size 600 x 360 pixels. Dim c As PieChart Set c = cd.PieChart(600, 360) ' Use the white on black palette, which means the default text and line colors are white Call c.setColors(cd.whiteOnBlackPalette) ' Use a vertical gradient color from deep blue (000066) to blue (0000cc) as background. Use ' rounded corners of 20 pixels radius. Enable soft drop shadow. Call c.setBackground(c.linearGradientColor(0, 0, 0, c.getHeight(), &H000066, &H0000cc)) Call c.setRoundedFrame(&Hffffff, 20) Call c.setDropShadow() ' Add a title using 18pt Times New Roman Bold Italic font. Add 16 pixels top margin to the ' title. Call c.addTitle("Exploded Pie Chart Demonstration", "timesbi.ttf", 18).setMargin2(0, 0, 16, 0) ' Set the center of the pie at (300, 195) and the radius to 110 pixels Call c.setPieSize(300, 195, 110) ' Set the pie data and the pie labels Call c.setData(data, labels) ' Set the sector colors Call c.setColors2(cd.DataColor, colors) ' Use local gradient shading for the sectors, with 5 pixels wide semi-transparent white ' (bbffffff) borders Call c.setSectorStyle(cd.LocalGradientShading, &Hbbffffff, 5) ' Use the side label layout method Call c.setLabelLayout(cd.SideLayout) ' Use 10pt Arial Bold as the default label font. Set the label box background color the same as ' the sector color. Use soft lighting effect with light direction from right. Use 8 pixels ' rounded corners. Dim t As ChartDirector.TextBox Set t = c.setLabelStyle("arialbd.ttf", 10, &H000000) Call t.setBackground(cd.SameAsMainColor, cd.Transparent, cd.softLighting(cd.Right, 0)) Call t.setRoundedCorners(8) ' Set the sector label format. The label is centered in a 110 pixels wide bounding box. It ' consists of two lines. The first line is the sector name. The second line shows the data value ' and percentage. Call c.setLabelFormat( _ "<*block,halign=center,width=110*>{label}<*br*><*font=arial.ttf,size=8*>US$ {value}M " & _ "({percent}%)<*/*>") ' Explode all sectors 10 pixels from the center Call c.setExplode(-1, 10) ' Output the chart Set viewer.Picture = c.makePicture() 'include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", _ "title='{label}: US${value}M ({percent}%)'") End Sub