ChartDirector 7.1 (.NET Edition)

Simple Rose Chart




This example demonstrates how to create a rose chart.

A rose chart is basically a polar chart with sectors of variable radius. This can be achieved by creating a PolarChart object as the graph paper, and adding sector zones on it using AngularAxis.addZone.

To enable auto-scale of the axis, in this example, we also add the radius data to a transparent line layer using PolarChart.addLineLayer. The line layer has no visible effect, but it causes the radial axis to auto-scale so that it covers the radius data.

Source Code Listing

[Windows Forms - C# version] NetWinCharts\CSharpWinCharts\rose.cs
using System; using ChartDirector; namespace CSharpChartExplorer { public class rose : DemoModule { //Name of demo module public string getName() { return "Simple Rose Chart"; } //Number of charts produced in this demo module public int getNoOfCharts() { return 1; } //Main code for creating chart. //Note: the argument chartIndex is unused because this demo only has 1 chart. public void createChart(WinChartViewer viewer, int chartIndex) { // Data for the chart double[] data = {9.4, 1.8, 2.1, 2.3, 3.5, 7.7, 8.8, 6.1, 5.0, 3.1, 6.0, 4.3, 5.1, 2.6, 1.5, 2.2, 5.1, 4.3, 4.0, 9.0, 1.7, 8.8, 9.9, 9.5}; double[] angles = {0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300, 315, 330, 345}; // Create a PolarChart object of size 460 x 460 pixels, with a silver background and a 1 // pixel 3D border PolarChart c = new PolarChart(460, 460, Chart.silverColor(), 0x000000, 1); // Add a title to the chart at the top left corner using 15pt Arial Bold Italic font. // Use white text on deep blue background. c.addTitle("Polar Vector Chart Demonstration", "Arial Bold Italic", 15, 0xffffff ).setBackground(0x000080); // Set plot area center at (230, 240) with radius 180 pixels and white background c.setPlotArea(230, 240, 180, 0xffffff); // Set the grid style to circular grid c.setGridStyle(false); // Set angular axis as 0 - 360, with a spoke every 30 units c.angularAxis().setLinearScale(0, 360, 30); // Add sectors to the chart as sector zones for(int i = 0; i < data.Length; ++i) { c.angularAxis().addZone(angles[i], angles[i] + 15, 0, data[i], 0x33ff33, 0x008000); } // Add an Transparent invisible layer to ensure the axis is auto-scaled using the data c.addLineLayer(data, Chart.Transparent); // Output the chart viewer.Chart = c; } } }

[Windows Forms - VB Version] NetWinCharts\VBNetWinCharts\rose.vb
Imports System Imports Microsoft.VisualBasic Imports ChartDirector Public Class rose Implements DemoModule 'Name of demo module Public Function getName() As String Implements DemoModule.getName Return "Simple Rose Chart" End Function 'Number of charts produced in this demo module Public Function getNoOfCharts() As Integer Implements DemoModule.getNoOfCharts Return 1 End Function 'Main code for creating chart. 'Note: the argument chartIndex is unused because this demo only has 1 chart. Public Sub createChart(viewer As WinChartViewer, chartIndex As Integer) _ Implements DemoModule.createChart ' Data for the chart Dim data() As Double = {9.4, 1.8, 2.1, 2.3, 3.5, 7.7, 8.8, 6.1, 5.0, 3.1, 6.0, 4.3, 5.1, _ 2.6, 1.5, 2.2, 5.1, 4.3, 4.0, 9.0, 1.7, 8.8, 9.9, 9.5} Dim angles() As Double = {0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, _ 210, 225, 240, 255, 270, 285, 300, 315, 330, 345} ' Create a PolarChart object of size 460 x 460 pixels, with a silver background and a 1 ' pixel 3D border Dim c As PolarChart = New PolarChart(460, 460, Chart.silverColor(), &H000000, 1) ' Add a title to the chart at the top left corner using 15pt Arial Bold Italic font. Use ' white text on deep blue background. c.addTitle("Polar Vector Chart Demonstration", "Arial Bold Italic", 15, &Hffffff _ ).setBackground(&H000080) ' Set plot area center at (230, 240) with radius 180 pixels and white background c.setPlotArea(230, 240, 180, &Hffffff) ' Set the grid style to circular grid c.setGridStyle(False) ' Set angular axis as 0 - 360, with a spoke every 30 units c.angularAxis().setLinearScale(0, 360, 30) ' Add sectors to the chart as sector zones For i As Integer = 0 To UBound(data) c.angularAxis().addZone(angles(i), angles(i) + 15, 0, data(i), &H33ff33, &H008000) Next ' Add an Transparent invisible layer to ensure the axis is auto-scaled using the data c.addLineLayer(data, Chart.Transparent) ' Output the chart viewer.Chart = c End Sub End Class

[WPF - C#] NetWPFCharts\CSharpWPFCharts\rose.cs
using System; using ChartDirector; namespace CSharpWPFCharts { public class rose : DemoModule { //Name of demo module public string getName() { return "Simple Rose Chart"; } //Number of charts produced in this demo module public int getNoOfCharts() { return 1; } //Main code for creating chart. //Note: the argument chartIndex is unused because this demo only has 1 chart. public void createChart(WPFChartViewer viewer, int chartIndex) { // Data for the chart double[] data = {9.4, 1.8, 2.1, 2.3, 3.5, 7.7, 8.8, 6.1, 5.0, 3.1, 6.0, 4.3, 5.1, 2.6, 1.5, 2.2, 5.1, 4.3, 4.0, 9.0, 1.7, 8.8, 9.9, 9.5}; double[] angles = {0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300, 315, 330, 345}; // Create a PolarChart object of size 460 x 460 pixels, with a silver background and a 1 // pixel 3D border PolarChart c = new PolarChart(460, 460, Chart.silverColor(), 0x000000, 1); // Add a title to the chart at the top left corner using 15pt Arial Bold Italic font. // Use white text on deep blue background. c.addTitle("Polar Vector Chart Demonstration", "Arial Bold Italic", 15, 0xffffff ).setBackground(0x000080); // Set plot area center at (230, 240) with radius 180 pixels and white background c.setPlotArea(230, 240, 180, 0xffffff); // Set the grid style to circular grid c.setGridStyle(false); // Set angular axis as 0 - 360, with a spoke every 30 units c.angularAxis().setLinearScale(0, 360, 30); // Add sectors to the chart as sector zones for(int i = 0; i < data.Length; ++i) { c.angularAxis().addZone(angles[i], angles[i] + 15, 0, data[i], 0x33ff33, 0x008000); } // Add an Transparent invisible layer to ensure the axis is auto-scaled using the data c.addLineLayer(data, Chart.Transparent); // Output the chart viewer.Chart = c; } } }

[ASP.NET Web Forms - C# version] NetWebCharts\CSharpASP\rose.aspx
(Click here on how to convert this code to code-behind style.)
<%@ Page Language="C#" Debug="true" %> <%@ Import Namespace="ChartDirector" %> <%@ Register TagPrefix="chart" Namespace="ChartDirector" Assembly="netchartdir" %> <!DOCTYPE html> <script runat="server"> // // Page Load event handler // protected void Page_Load(object sender, EventArgs e) { // Data for the chart double[] data = {9.4, 1.8, 2.1, 2.3, 3.5, 7.7, 8.8, 6.1, 5.0, 3.1, 6.0, 4.3, 5.1, 2.6, 1.5, 2.2, 5.1, 4.3, 4.0, 9.0, 1.7, 8.8, 9.9, 9.5}; double[] angles = {0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300, 315, 330, 345}; // Create a PolarChart object of size 460 x 460 pixels, with a silver background and a 1 pixel // 3D border PolarChart c = new PolarChart(460, 460, Chart.silverColor(), 0x000000, 1); // Add a title to the chart at the top left corner using 15pt Arial Bold Italic font. Use white // text on deep blue background. c.addTitle("Polar Vector Chart Demonstration", "Arial Bold Italic", 15, 0xffffff).setBackground( 0x000080); // Set plot area center at (230, 240) with radius 180 pixels and white background c.setPlotArea(230, 240, 180, 0xffffff); // Set the grid style to circular grid c.setGridStyle(false); // Set angular axis as 0 - 360, with a spoke every 30 units c.angularAxis().setLinearScale(0, 360, 30); // Add sectors to the chart as sector zones for(int i = 0; i < data.Length; ++i) { c.angularAxis().addZone(angles[i], angles[i] + 15, 0, data[i], 0x33ff33, 0x008000); } // Add an Transparent invisible layer to ensure the axis is auto-scaled using the data c.addLineLayer(data, Chart.Transparent); // Output the chart WebChartViewer1.Image = c.makeWebImage(Chart.SVG); } </script> <html> <head> <script type="text/javascript" src="cdjcv.js"></script> </head> <body> <chart:WebChartViewer id="WebChartViewer1" runat="server" /> </body> </html>

[ASP.NET Web Forms - VB Version] NetWebCharts\VBNetASP\rose.aspx
(Click here on how to convert this code to code-behind style.)
<%@ Page Language="VB" Debug="true" %> <%@ Import Namespace="ChartDirector" %> <%@ Register TagPrefix="chart" Namespace="ChartDirector" Assembly="netchartdir" %> <!DOCTYPE html> <script runat="server"> ' ' Page Load event handler ' Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Data for the chart Dim data() As Double = {9.4, 1.8, 2.1, 2.3, 3.5, 7.7, 8.8, 6.1, 5.0, 3.1, 6.0, 4.3, 5.1, 2.6, _ 1.5, 2.2, 5.1, 4.3, 4.0, 9.0, 1.7, 8.8, 9.9, 9.5} Dim angles() As Double = {0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, _ 225, 240, 255, 270, 285, 300, 315, 330, 345} ' Create a PolarChart object of size 460 x 460 pixels, with a silver background and a 1 pixel 3D ' border Dim c As PolarChart = New PolarChart(460, 460, Chart.silverColor(), &H000000, 1) ' Add a title to the chart at the top left corner using 15pt Arial Bold Italic font. Use white ' text on deep blue background. c.addTitle("Polar Vector Chart Demonstration", "Arial Bold Italic", 15, &Hffffff _ ).setBackground(&H000080) ' Set plot area center at (230, 240) with radius 180 pixels and white background c.setPlotArea(230, 240, 180, &Hffffff) ' Set the grid style to circular grid c.setGridStyle(False) ' Set angular axis as 0 - 360, with a spoke every 30 units c.angularAxis().setLinearScale(0, 360, 30) ' Add sectors to the chart as sector zones For i As Integer = 0 To UBound(data) c.angularAxis().addZone(angles(i), angles(i) + 15, 0, data(i), &H33ff33, &H008000) Next ' Add an Transparent invisible layer to ensure the axis is auto-scaled using the data c.addLineLayer(data, Chart.Transparent) ' Output the chart WebChartViewer1.Image = c.makeWebImage(Chart.SVG) End Sub </script> <html> <head> <script type="text/javascript" src="cdjcv.js"></script> </head> <body> <chart:WebChartViewer id="WebChartViewer1" runat="server" /> </body> </html>

[ASP.NET MVC - Controller] NetMvcCharts\Controllers\RoseController.cs
using System; using System.Web.Mvc; using ChartDirector; namespace NetMvcCharts.Controllers { public class RoseController : Controller { // // Default Action // public ActionResult Index() { ViewBag.Title = "Simple Rose Chart"; createChart(ViewBag.Viewer = new RazorChartViewer(HttpContext, "chart1")); return View("~/Views/Shared/ChartView.cshtml"); } // // Create chart // private void createChart(RazorChartViewer viewer) { // Data for the chart double[] data = {9.4, 1.8, 2.1, 2.3, 3.5, 7.7, 8.8, 6.1, 5.0, 3.1, 6.0, 4.3, 5.1, 2.6, 1.5, 2.2, 5.1, 4.3, 4.0, 9.0, 1.7, 8.8, 9.9, 9.5}; double[] angles = {0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300, 315, 330, 345}; // Create a PolarChart object of size 460 x 460 pixels, with a silver background and a 1 // pixel 3D border PolarChart c = new PolarChart(460, 460, Chart.silverColor(), 0x000000, 1); // Add a title to the chart at the top left corner using 15pt Arial Bold Italic font. Use // white text on deep blue background. c.addTitle("Polar Vector Chart Demonstration", "Arial Bold Italic", 15, 0xffffff ).setBackground(0x000080); // Set plot area center at (230, 240) with radius 180 pixels and white background c.setPlotArea(230, 240, 180, 0xffffff); // Set the grid style to circular grid c.setGridStyle(false); // Set angular axis as 0 - 360, with a spoke every 30 units c.angularAxis().setLinearScale(0, 360, 30); // Add sectors to the chart as sector zones for(int i = 0; i < data.Length; ++i) { c.angularAxis().addZone(angles[i], angles[i] + 15, 0, data[i], 0x33ff33, 0x008000); } // Add an Transparent invisible layer to ensure the axis is auto-scaled using the data c.addLineLayer(data, Chart.Transparent); // Output the chart viewer.Image = c.makeWebImage(Chart.SVG); } } }

[ASP.NET MVC - View] NetMvcCharts\Views\Shared\ChartView.cshtml
@{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>@ViewBag.Title</title> <style> @ViewBag.Style </style> @Scripts.Render("~/Scripts/cdjcv.js") </head> <body style="margin:5px 0px 0px 5px"> <div style="font:bold 18pt verdana;"> @ViewBag.Title </div> <hr style="border:solid 1px #000080; background:#000080" /> <div> @{ if (ViewBag.Viewer is Array) { // Display multiple charts for (int i = 0; i < ViewBag.Viewer.Length; ++i) { @:@Html.Raw(ViewBag.Viewer[i].RenderHTML()) } } else { // Display one chart only @:@Html.Raw(ViewBag.Viewer.RenderHTML()) } } </div> </body> </html>