ChartDirector 7.1 (.NET Edition)

Surface Lines and Zones




This examples demonstrates adding custom lines and zones on a surface chart.

Surface lines and zones are useful for marking regions or boundaries on the surface chart. In this example, surface lines are added using SurfaceChart.addSurfaceLine and SurfaceChart.addSurfaceLine2, and surface zones are added using SurfaceChart.addSurfaceZone. Semi-transparent colors are used so that the zones will not block the underlying surface. The "X" icon is added by adding two short surface lines, and the square icon is added by adding a small transparent zone with black border.

Source Code Listing

[Windows Forms - C# version] NetWinCharts\CSharpWinCharts\surfacelinezone.cs
using System; using ChartDirector; namespace CSharpChartExplorer { public class surfacelinezone : DemoModule { //Name of demo module public string getName() { return "Surface Lines and Zones"; } //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) { // The x and y coordinates of the grid double[] dataX = {-4, -3, -2, -1, 0, 1, 2, 3, 4}; double[] dataY = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // The values at the grid points. In this example, we will compute the values using the // formula z = 20 / (1 + 1 / (1 + 3.5 ** (x + 0.5))) - 10. double[] dataZ = new double[dataX.Length * dataY.Length]; for(int yIndex = 0; yIndex < dataY.Length; ++yIndex) { for(int xIndex = 0; xIndex < dataX.Length; ++xIndex) { dataZ[yIndex * dataX.Length + xIndex] = 20 / (1 + 1 / (1 + Math.Pow(3.5, dataX[ xIndex] + 0.5))) - 10; } } // Create a SurfaceChart object of size 720 x 600 pixels SurfaceChart c = new SurfaceChart(720, 600); // Set the center of the plot region at (350, 280), and set width x depth x height to // 360 x 360 x 270 pixels c.setPlotRegion(350, 280, 360, 360, 270); // Set the data to use to plot the chart c.setData(dataX, dataY, dataZ); // Spline interpolate data to a 80 x 80 grid for a smooth surface c.setInterpolation(80, 80); // Set the elevation and rotation angles to 30 and 315 degrees c.setViewAngle(45, 315); // Add a color axis (the legend) 20 pixels from the right border. Set the length to 200 // pixels and the labels on the right side. ColorAxis cAxis = c.setColorAxis(c.getWidth() - 20, 275, Chart.Right, 200, Chart.Right); // The color gradient used for the color axis int[] colorGradient = {0x00aa00, 0x66ff00, 0xffff00, 0xffcc00, 0xff0000}; cAxis.setColorGradient(false, colorGradient); // Add a semi-transparent blue (0x7f0000ff) rectangular surface zone with opposite // corners at (0, 1) and (1.6, 2) c.addSurfaceZone(0, 1, 1.6, 2, 0x7f0000ff, 0x7f0000ff, 2); // Add a semi-transparent grey (0x7fdddddd) rectangular surface zone with opposite // corners at (2, 7) and (3.5, 9.5) c.addSurfaceZone(2, 7, 3.5, 9.5, 0x7fdddddd, 0x7fdddddd, 2); // Add a surface line from (-4, 3) to (0, 10). Use brown (0x444400) dash line with a // line width of 2 pixels. c.addSurfaceLine(-4, 3, 0, 10, c.dashLineColor(0x444400), 2); // Add a surface line from (-2, 10) to (0, 5) to (1, 8) to (4, 0.5). Use purple color // with a line width of 2 pixels. double[] lineX = {-2, 0, 1, 4}; double[] lineY = {10, 5, 8, 0.5}; c.addSurfaceLine2(lineX, lineY, 0x880088, 2); // Add two surface lins to create a X symbol. c.addSurfaceLine(-1.4, 3.9, -1.6, 4.1, 0x000088, 2); c.addSurfaceLine(-1.6, 3.9, -1.4, 4.1, 0x000088, 2); // Add a small surface zone with transparent fill color and a 2-pixel border to create a // square symbol. c.addSurfaceZone(-1.4, 2.9, -1.6, 3.1, Chart.Transparent, 0x000088, 2); // Add a legend box align to the right edge of the chart. Use 10pt Arial Bold font. Set // the background and border to transparent. LegendBox b = c.addLegend(c.getWidth() - 1, 10, true, "Arial Bold", 10); b.setAlignment(Chart.TopRight); b.setBackground(Chart.Transparent, Chart.Transparent); // Set the legend icon size to 24 x 15 pixels. Set a gap of 10 pixels between the icon // and the text. b.setKeySize(24, 15, 10); // Add legend entries for the zones, lines and symbols b.addKey("Sample Zone 1", 0x7f0000ff); b.addKey("Sample Zone 2", 0x7fdddddd); b.addKey("Sample Line 1", 0x880088, 2); b.addKey("Sample Line 2", c.dashLineColor(0x444400), 2); b.addText( "<*block,width=24,halign=center*><*img=@Square,width=11,edgeColor=000000*><*/*>" + "<*advance=10*>Symbol 1"); b.addText( "<*block,width=24,halign=center*><*img=@Cross2(0.1),width=11,color=000000*><*/*>" + "<*advance=10*>Symbol 2"); // Set the x, y and z axis titles using 12pt Arial Bold font c.xAxis().setTitle("X Title<*br*>Placeholder", "Arial Bold", 12); c.yAxis().setTitle("Y Title<*br*>Placeholder", "Arial Bold", 12); c.zAxis().setTitle("Z Title Placeholder", "Arial Bold", 12); // Output the chart viewer.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='<*cdml*><*font=bold*>X: {x|2}<*br*>Y: {y|2}<*br*>Z: {z|2}'"); } } }

[Windows Forms - VB Version] NetWinCharts\VBNetWinCharts\surfacelinezone.vb
Imports System Imports Microsoft.VisualBasic Imports ChartDirector Public Class surfacelinezone Implements DemoModule 'Name of demo module Public Function getName() As String Implements DemoModule.getName Return "Surface Lines and Zones" 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 ' The x and y coordinates of the grid Dim dataX() As Double = {-4, -3, -2, -1, 0, 1, 2, 3, 4} Dim dataY() As Double = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} ' The values at the grid points. In this example, we will compute the values using the ' formula z = 20 / (1 + 1 / (1 + 3.5 ** (x + 0.5))) - 10. Dim dataZ((UBound(dataX) + 1) * (UBound(dataY) + 1) - 1) As Double For yIndex As Integer = 0 To UBound(dataY) For xIndex As Integer = 0 To UBound(dataX) dataZ(yIndex * (UBound(dataX) + 1) + xIndex) = 20 / (1 + 1 / (1 + 3.5 ^ dataX( _ xIndex) + 0.5)) - 10 Next Next ' Create a SurfaceChart object of size 720 x 600 pixels Dim c As SurfaceChart = New SurfaceChart(720, 600) ' Set the center of the plot region at (350, 280), and set width x depth x height to 360 x ' 360 x 270 pixels c.setPlotRegion(350, 280, 360, 360, 270) ' Set the data to use to plot the chart c.setData(dataX, dataY, dataZ) ' Spline interpolate data to a 80 x 80 grid for a smooth surface c.setInterpolation(80, 80) ' Set the elevation and rotation angles to 30 and 315 degrees c.setViewAngle(45, 315) ' Add a color axis (the legend) 20 pixels from the right border. Set the length to 200 ' pixels and the labels on the right side. Dim cAxis As ColorAxis = c.setColorAxis(c.getWidth() - 20, 275, Chart.Right, 200, _ Chart.Right) ' The color gradient used for the color axis Dim colorGradient() As Integer = {&H00aa00, &H66ff00, &Hffff00, &Hffcc00, &Hff0000} cAxis.setColorGradient(False, colorGradient) ' Add a semi-transparent blue (0x7f0000ff) rectangular surface zone with opposite corners at ' (0, 1) and (1.6, 2) c.addSurfaceZone(0, 1, 1.6, 2, &H7f0000ff, &H7f0000ff, 2) ' Add a semi-transparent grey (0x7fdddddd) rectangular surface zone with opposite corners at ' (2, 7) and (3.5, 9.5) c.addSurfaceZone(2, 7, 3.5, 9.5, &H7fdddddd, &H7fdddddd, 2) ' Add a surface line from (-4, 3) to (0, 10). Use brown (0x444400) dash line with a line ' width of 2 pixels. c.addSurfaceLine(-4, 3, 0, 10, c.dashLineColor(&H444400), 2) ' Add a surface line from (-2, 10) to (0, 5) to (1, 8) to (4, 0.5). Use purple color with a ' line width of 2 pixels. Dim lineX() As Double = {-2, 0, 1, 4} Dim lineY() As Double = {10, 5, 8, 0.5} c.addSurfaceLine2(lineX, lineY, &H880088, 2) ' Add two surface lins to create a X symbol. c.addSurfaceLine(-1.4, 3.9, -1.6, 4.1, &H000088, 2) c.addSurfaceLine(-1.6, 3.9, -1.4, 4.1, &H000088, 2) ' Add a small surface zone with transparent fill color and a 2-pixel border to create a ' square symbol. c.addSurfaceZone(-1.4, 2.9, -1.6, 3.1, Chart.Transparent, &H000088, 2) ' Add a legend box align to the right edge of the chart. Use 10pt Arial Bold font. Set the ' background and border to transparent. Dim b As LegendBox = c.addLegend(c.getWidth() - 1, 10, True, "Arial Bold", 10) b.setAlignment(Chart.TopRight) b.setBackground(Chart.Transparent, Chart.Transparent) ' Set the legend icon size to 24 x 15 pixels. Set a gap of 10 pixels between the icon and ' the text. b.setKeySize(24, 15, 10) ' Add legend entries for the zones, lines and symbols b.addKey("Sample Zone 1", &H7f0000ff) b.addKey("Sample Zone 2", &H7fdddddd) b.addKey("Sample Line 1", &H880088, 2) b.addKey("Sample Line 2", c.dashLineColor(&H444400), 2) b.addText( _ "<*block,width=24,halign=center*><*img=@Square,width=11,edgeColor=000000*><*/*>" & _ "<*advance=10*>Symbol 1") b.addText( _ "<*block,width=24,halign=center*><*img=@Cross2(0.1),width=11,color=000000*><*/*>" & _ "<*advance=10*>Symbol 2") ' Set the x, y and z axis titles using 12pt Arial Bold font c.xAxis().setTitle("X Title<*br*>Placeholder", "Arial Bold", 12) c.yAxis().setTitle("Y Title<*br*>Placeholder", "Arial Bold", 12) c.zAxis().setTitle("Z Title Placeholder", "Arial Bold", 12) ' Output the chart viewer.Chart = c 'include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", _ "title='<*cdml*><*font=bold*>X: {x|2}<*br*>Y: {y|2}<*br*>Z: {z|2}'") End Sub End Class

[WPF - C#] NetWPFCharts\CSharpWPFCharts\surfacelinezone.cs
using System; using ChartDirector; namespace CSharpWPFCharts { public class surfacelinezone : DemoModule { //Name of demo module public string getName() { return "Surface Lines and Zones"; } //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) { // The x and y coordinates of the grid double[] dataX = {-4, -3, -2, -1, 0, 1, 2, 3, 4}; double[] dataY = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // The values at the grid points. In this example, we will compute the values using the // formula z = 20 / (1 + 1 / (1 + 3.5 ** (x + 0.5))) - 10. double[] dataZ = new double[dataX.Length * dataY.Length]; for(int yIndex = 0; yIndex < dataY.Length; ++yIndex) { for(int xIndex = 0; xIndex < dataX.Length; ++xIndex) { dataZ[yIndex * dataX.Length + xIndex] = 20 / (1 + 1 / (1 + Math.Pow(3.5, dataX[ xIndex] + 0.5))) - 10; } } // Create a SurfaceChart object of size 720 x 600 pixels SurfaceChart c = new SurfaceChart(720, 600); // Set the center of the plot region at (350, 280), and set width x depth x height to // 360 x 360 x 270 pixels c.setPlotRegion(350, 280, 360, 360, 270); // Set the data to use to plot the chart c.setData(dataX, dataY, dataZ); // Spline interpolate data to a 80 x 80 grid for a smooth surface c.setInterpolation(80, 80); // Set the elevation and rotation angles to 30 and 315 degrees c.setViewAngle(45, 315); // Add a color axis (the legend) 20 pixels from the right border. Set the length to 200 // pixels and the labels on the right side. ColorAxis cAxis = c.setColorAxis(c.getWidth() - 20, 275, Chart.Right, 200, Chart.Right); // The color gradient used for the color axis int[] colorGradient = {0x00aa00, 0x66ff00, 0xffff00, 0xffcc00, 0xff0000}; cAxis.setColorGradient(false, colorGradient); // Add a semi-transparent blue (0x7f0000ff) rectangular surface zone with opposite // corners at (0, 1) and (1.6, 2) c.addSurfaceZone(0, 1, 1.6, 2, 0x7f0000ff, 0x7f0000ff, 2); // Add a semi-transparent grey (0x7fdddddd) rectangular surface zone with opposite // corners at (2, 7) and (3.5, 9.5) c.addSurfaceZone(2, 7, 3.5, 9.5, 0x7fdddddd, 0x7fdddddd, 2); // Add a surface line from (-4, 3) to (0, 10). Use brown (0x444400) dash line with a // line width of 2 pixels. c.addSurfaceLine(-4, 3, 0, 10, c.dashLineColor(0x444400), 2); // Add a surface line from (-2, 10) to (0, 5) to (1, 8) to (4, 0.5). Use purple color // with a line width of 2 pixels. double[] lineX = {-2, 0, 1, 4}; double[] lineY = {10, 5, 8, 0.5}; c.addSurfaceLine2(lineX, lineY, 0x880088, 2); // Add two surface lins to create a X symbol. c.addSurfaceLine(-1.4, 3.9, -1.6, 4.1, 0x000088, 2); c.addSurfaceLine(-1.6, 3.9, -1.4, 4.1, 0x000088, 2); // Add a small surface zone with transparent fill color and a 2-pixel border to create a // square symbol. c.addSurfaceZone(-1.4, 2.9, -1.6, 3.1, Chart.Transparent, 0x000088, 2); // Add a legend box align to the right edge of the chart. Use 10pt Arial Bold font. Set // the background and border to transparent. LegendBox b = c.addLegend(c.getWidth() - 1, 10, true, "Arial Bold", 10); b.setAlignment(Chart.TopRight); b.setBackground(Chart.Transparent, Chart.Transparent); // Set the legend icon size to 24 x 15 pixels. Set a gap of 10 pixels between the icon // and the text. b.setKeySize(24, 15, 10); // Add legend entries for the zones, lines and symbols b.addKey("Sample Zone 1", 0x7f0000ff); b.addKey("Sample Zone 2", 0x7fdddddd); b.addKey("Sample Line 1", 0x880088, 2); b.addKey("Sample Line 2", c.dashLineColor(0x444400), 2); b.addText( "<*block,width=24,halign=center*><*img=@Square,width=11,edgeColor=000000*><*/*>" + "<*advance=10*>Symbol 1"); b.addText( "<*block,width=24,halign=center*><*img=@Cross2(0.1),width=11,color=000000*><*/*>" + "<*advance=10*>Symbol 2"); // Set the x, y and z axis titles using 12pt Arial Bold font c.xAxis().setTitle("X Title<*br*>Placeholder", "Arial Bold", 12); c.yAxis().setTitle("Y Title<*br*>Placeholder", "Arial Bold", 12); c.zAxis().setTitle("Z Title Placeholder", "Arial Bold", 12); // Output the chart viewer.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='<*cdml*><*font=bold*>X: {x|2}<*br*>Y: {y|2}<*br*>Z: {z|2}'"); } } }

[ASP.NET Web Forms - C# version] NetWebCharts\CSharpASP\surfacelinezone.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) { // The x and y coordinates of the grid double[] dataX = {-4, -3, -2, -1, 0, 1, 2, 3, 4}; double[] dataY = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // The values at the grid points. In this example, we will compute the values using the formula // z = 20 / (1 + 1 / (1 + 3.5 ** (x + 0.5))) - 10. double[] dataZ = new double[dataX.Length * dataY.Length]; for(int yIndex = 0; yIndex < dataY.Length; ++yIndex) { for(int xIndex = 0; xIndex < dataX.Length; ++xIndex) { dataZ[yIndex * dataX.Length + xIndex] = 20 / (1 + 1 / (1 + Math.Pow(3.5, dataX[xIndex] + 0.5))) - 10; } } // Create a SurfaceChart object of size 720 x 600 pixels SurfaceChart c = new SurfaceChart(720, 600); // Set the center of the plot region at (350, 280), and set width x depth x height to 360 x 360 // x 270 pixels c.setPlotRegion(350, 280, 360, 360, 270); // Set the data to use to plot the chart c.setData(dataX, dataY, dataZ); // Spline interpolate data to a 80 x 80 grid for a smooth surface c.setInterpolation(80, 80); // Set the elevation and rotation angles to 30 and 315 degrees c.setViewAngle(45, 315); // Add a color axis (the legend) 20 pixels from the right border. Set the length to 200 pixels // and the labels on the right side. ColorAxis cAxis = c.setColorAxis(c.getWidth() - 20, 275, Chart.Right, 200, Chart.Right); // The color gradient used for the color axis int[] colorGradient = {0x00aa00, 0x66ff00, 0xffff00, 0xffcc00, 0xff0000}; cAxis.setColorGradient(false, colorGradient); // Add a semi-transparent blue (0x7f0000ff) rectangular surface zone with opposite corners at // (0, 1) and (1.6, 2) c.addSurfaceZone(0, 1, 1.6, 2, 0x7f0000ff, 0x7f0000ff, 2); // Add a semi-transparent grey (0x7fdddddd) rectangular surface zone with opposite corners at // (2, 7) and (3.5, 9.5) c.addSurfaceZone(2, 7, 3.5, 9.5, 0x7fdddddd, 0x7fdddddd, 2); // Add a surface line from (-4, 3) to (0, 10). Use brown (0x444400) dash line with a line width // of 2 pixels. c.addSurfaceLine(-4, 3, 0, 10, c.dashLineColor(0x444400), 2); // Add a surface line from (-2, 10) to (0, 5) to (1, 8) to (4, 0.5). Use purple color with a // line width of 2 pixels. double[] lineX = {-2, 0, 1, 4}; double[] lineY = {10, 5, 8, 0.5}; c.addSurfaceLine2(lineX, lineY, 0x880088, 2); // Add two surface lins to create a X symbol. c.addSurfaceLine(-1.4, 3.9, -1.6, 4.1, 0x000088, 2); c.addSurfaceLine(-1.6, 3.9, -1.4, 4.1, 0x000088, 2); // Add a small surface zone with transparent fill color and a 2-pixel border to create a square // symbol. c.addSurfaceZone(-1.4, 2.9, -1.6, 3.1, Chart.Transparent, 0x000088, 2); // Add a legend box align to the right edge of the chart. Use 10pt Arial Bold font. Set the // background and border to transparent. LegendBox b = c.addLegend(c.getWidth() - 1, 10, true, "Arial Bold", 10); b.setAlignment(Chart.TopRight); b.setBackground(Chart.Transparent, Chart.Transparent); // Set the legend icon size to 24 x 15 pixels. Set a gap of 10 pixels between the icon and the // text. b.setKeySize(24, 15, 10); // Add legend entries for the zones, lines and symbols b.addKey("Sample Zone 1", 0x7f0000ff); b.addKey("Sample Zone 2", 0x7fdddddd); b.addKey("Sample Line 1", 0x880088, 2); b.addKey("Sample Line 2", c.dashLineColor(0x444400), 2); b.addText( "<*block,width=24,halign=center*><*img=@Square,width=11,edgeColor=000000*><*/*>" + "<*advance=10*>Symbol 1"); b.addText( "<*block,width=24,halign=center*><*img=@Cross2(0.1),width=11,color=000000*><*/*>" + "<*advance=10*>Symbol 2"); // Set the x, y and z axis titles using 12pt Arial Bold font c.xAxis().setTitle("X Title<*br*>Placeholder", "Arial Bold", 12); c.yAxis().setTitle("Y Title<*br*>Placeholder", "Arial Bold", 12); c.zAxis().setTitle("Z Title Placeholder", "Arial Bold", 12); // 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\surfacelinezone.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) ' The x and y coordinates of the grid Dim dataX() As Double = {-4, -3, -2, -1, 0, 1, 2, 3, 4} Dim dataY() As Double = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} ' The values at the grid points. In this example, we will compute the values using the formula z ' = 20 / (1 + 1 / (1 + 3.5 ** (x + 0.5))) - 10. Dim dataZ((UBound(dataX) + 1) * (UBound(dataY) + 1) - 1) As Double For yIndex As Integer = 0 To UBound(dataY) For xIndex As Integer = 0 To UBound(dataX) dataZ(yIndex * (UBound(dataX) + 1) + xIndex) = 20 / (1 + 1 / (1 + 3.5 ^ (dataX(xIndex) _ + 0.5))) - 10 Next Next ' Create a SurfaceChart object of size 720 x 600 pixels Dim c As SurfaceChart = New SurfaceChart(720, 600) ' Set the center of the plot region at (350, 280), and set width x depth x height to 360 x 360 x ' 270 pixels c.setPlotRegion(350, 280, 360, 360, 270) ' Set the data to use to plot the chart c.setData(dataX, dataY, dataZ) ' Spline interpolate data to a 80 x 80 grid for a smooth surface c.setInterpolation(80, 80) ' Set the elevation and rotation angles to 30 and 315 degrees c.setViewAngle(45, 315) ' Add a color axis (the legend) 20 pixels from the right border. Set the length to 200 pixels ' and the labels on the right side. Dim cAxis As ColorAxis = c.setColorAxis(c.getWidth() - 20, 275, Chart.Right, 200, Chart.Right) ' The color gradient used for the color axis Dim colorGradient() As Integer = {&H00aa00, &H66ff00, &Hffff00, &Hffcc00, &Hff0000} cAxis.setColorGradient(False, colorGradient) ' Add a semi-transparent blue (0x7f0000ff) rectangular surface zone with opposite corners at (0, ' 1) and (1.6, 2) c.addSurfaceZone(0, 1, 1.6, 2, &H7f0000ff, &H7f0000ff, 2) ' Add a semi-transparent grey (0x7fdddddd) rectangular surface zone with opposite corners at (2, ' 7) and (3.5, 9.5) c.addSurfaceZone(2, 7, 3.5, 9.5, &H7fdddddd, &H7fdddddd, 2) ' Add a surface line from (-4, 3) to (0, 10). Use brown (0x444400) dash line with a line width ' of 2 pixels. c.addSurfaceLine(-4, 3, 0, 10, c.dashLineColor(&H444400), 2) ' Add a surface line from (-2, 10) to (0, 5) to (1, 8) to (4, 0.5). Use purple color with a line ' width of 2 pixels. Dim lineX() As Double = {-2, 0, 1, 4} Dim lineY() As Double = {10, 5, 8, 0.5} c.addSurfaceLine2(lineX, lineY, &H880088, 2) ' Add two surface lins to create a X symbol. c.addSurfaceLine(-1.4, 3.9, -1.6, 4.1, &H000088, 2) c.addSurfaceLine(-1.6, 3.9, -1.4, 4.1, &H000088, 2) ' Add a small surface zone with transparent fill color and a 2-pixel border to create a square ' symbol. c.addSurfaceZone(-1.4, 2.9, -1.6, 3.1, Chart.Transparent, &H000088, 2) ' Add a legend box align to the right edge of the chart. Use 10pt Arial Bold font. Set the ' background and border to transparent. Dim b As LegendBox = c.addLegend(c.getWidth() - 1, 10, True, "Arial Bold", 10) b.setAlignment(Chart.TopRight) b.setBackground(Chart.Transparent, Chart.Transparent) ' Set the legend icon size to 24 x 15 pixels. Set a gap of 10 pixels between the icon and the ' text. b.setKeySize(24, 15, 10) ' Add legend entries for the zones, lines and symbols b.addKey("Sample Zone 1", &H7f0000ff) b.addKey("Sample Zone 2", &H7fdddddd) b.addKey("Sample Line 1", &H880088, 2) b.addKey("Sample Line 2", c.dashLineColor(&H444400), 2) b.addText( _ "<*block,width=24,halign=center*><*img=@Square,width=11,edgeColor=000000*><*/*>" & _ "<*advance=10*>Symbol 1") b.addText( _ "<*block,width=24,halign=center*><*img=@Cross2(0.1),width=11,color=000000*><*/*>" & _ "<*advance=10*>Symbol 2") ' Set the x, y and z axis titles using 12pt Arial Bold font c.xAxis().setTitle("X Title<*br*>Placeholder", "Arial Bold", 12) c.yAxis().setTitle("Y Title<*br*>Placeholder", "Arial Bold", 12) c.zAxis().setTitle("Z Title Placeholder", "Arial Bold", 12) ' 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\SurfacelinezoneController.cs
using System; using System.Web.Mvc; using ChartDirector; namespace NetMvcCharts.Controllers { public class SurfacelinezoneController : Controller { // // Default Action // public ActionResult Index() { ViewBag.Title = "Surface Lines and Zones"; createChart(ViewBag.Viewer = new RazorChartViewer(HttpContext, "chart1")); return View("~/Views/Shared/ChartView.cshtml"); } // // Create chart // private void createChart(RazorChartViewer viewer) { // The x and y coordinates of the grid double[] dataX = {-4, -3, -2, -1, 0, 1, 2, 3, 4}; double[] dataY = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // The values at the grid points. In this example, we will compute the values using the // formula z = 20 / (1 + 1 / (1 + 3.5 ** (x + 0.5))) - 10. double[] dataZ = new double[dataX.Length * dataY.Length]; for(int yIndex = 0; yIndex < dataY.Length; ++yIndex) { for(int xIndex = 0; xIndex < dataX.Length; ++xIndex) { dataZ[yIndex * dataX.Length + xIndex] = 20 / (1 + 1 / (1 + Math.Pow(3.5, dataX[xIndex ] + 0.5))) - 10; } } // Create a SurfaceChart object of size 720 x 600 pixels SurfaceChart c = new SurfaceChart(720, 600); // Set the center of the plot region at (350, 280), and set width x depth x height to 360 x // 360 x 270 pixels c.setPlotRegion(350, 280, 360, 360, 270); // Set the data to use to plot the chart c.setData(dataX, dataY, dataZ); // Spline interpolate data to a 80 x 80 grid for a smooth surface c.setInterpolation(80, 80); // Set the elevation and rotation angles to 30 and 315 degrees c.setViewAngle(45, 315); // Add a color axis (the legend) 20 pixels from the right border. Set the length to 200 // pixels and the labels on the right side. ColorAxis cAxis = c.setColorAxis(c.getWidth() - 20, 275, Chart.Right, 200, Chart.Right); // The color gradient used for the color axis int[] colorGradient = {0x00aa00, 0x66ff00, 0xffff00, 0xffcc00, 0xff0000}; cAxis.setColorGradient(false, colorGradient); // Add a semi-transparent blue (0x7f0000ff) rectangular surface zone with opposite corners at // (0, 1) and (1.6, 2) c.addSurfaceZone(0, 1, 1.6, 2, 0x7f0000ff, 0x7f0000ff, 2); // Add a semi-transparent grey (0x7fdddddd) rectangular surface zone with opposite corners at // (2, 7) and (3.5, 9.5) c.addSurfaceZone(2, 7, 3.5, 9.5, 0x7fdddddd, 0x7fdddddd, 2); // Add a surface line from (-4, 3) to (0, 10). Use brown (0x444400) dash line with a line // width of 2 pixels. c.addSurfaceLine(-4, 3, 0, 10, c.dashLineColor(0x444400), 2); // Add a surface line from (-2, 10) to (0, 5) to (1, 8) to (4, 0.5). Use purple color with a // line width of 2 pixels. double[] lineX = {-2, 0, 1, 4}; double[] lineY = {10, 5, 8, 0.5}; c.addSurfaceLine2(lineX, lineY, 0x880088, 2); // Add two surface lins to create a X symbol. c.addSurfaceLine(-1.4, 3.9, -1.6, 4.1, 0x000088, 2); c.addSurfaceLine(-1.6, 3.9, -1.4, 4.1, 0x000088, 2); // Add a small surface zone with transparent fill color and a 2-pixel border to create a // square symbol. c.addSurfaceZone(-1.4, 2.9, -1.6, 3.1, Chart.Transparent, 0x000088, 2); // Add a legend box align to the right edge of the chart. Use 10pt Arial Bold font. Set the // background and border to transparent. LegendBox b = c.addLegend(c.getWidth() - 1, 10, true, "Arial Bold", 10); b.setAlignment(Chart.TopRight); b.setBackground(Chart.Transparent, Chart.Transparent); // Set the legend icon size to 24 x 15 pixels. Set a gap of 10 pixels between the icon and // the text. b.setKeySize(24, 15, 10); // Add legend entries for the zones, lines and symbols b.addKey("Sample Zone 1", 0x7f0000ff); b.addKey("Sample Zone 2", 0x7fdddddd); b.addKey("Sample Line 1", 0x880088, 2); b.addKey("Sample Line 2", c.dashLineColor(0x444400), 2); b.addText( "<*block,width=24,halign=center*><*img=@Square,width=11,edgeColor=000000*><*/*>" + "<*advance=10*>Symbol 1"); b.addText( "<*block,width=24,halign=center*><*img=@Cross2(0.1),width=11,color=000000*><*/*>" + "<*advance=10*>Symbol 2"); // Set the x, y and z axis titles using 12pt Arial Bold font c.xAxis().setTitle("X Title<*br*>Placeholder", "Arial Bold", 12); c.yAxis().setTitle("Y Title<*br*>Placeholder", "Arial Bold", 12); c.zAxis().setTitle("Z Title Placeholder", "Arial Bold", 12); // 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>