ChartDirector 7.1 (.NET Edition)
Surface Projection
Source Code Listing
using System;
using ChartDirector;
namespace CSharpChartExplorer
{
public class surfaceprojection : DemoModule
{
//Name of demo module
public string getName() { return "Surface Projection"; }
//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 = {0, 1, 2, 3, 4, 5, 6, 7, 8};
double[] dataY = {0, 1, 2, 3, 4, 5, 6, 7, 8};
// Use random numbers for the z values on the XY grid
RanSeries r = new RanSeries(11);
double[] dataZ = r.get2DSeries(dataX.Length, dataY.Length, 0.1, 1.9);
// Create a SurfaceChart object of size 680 x 580 pixels
SurfaceChart c = new SurfaceChart(680, 580);
// Set the center of the plot region at (310, 280), and set width x depth x height to
// 320 x 320 x 240 pixels
c.setPlotRegion(310, 280, 320, 320, 240);
// Set the elevation and rotation angles to 30 and 45 degrees
c.setViewAngle(30, 45);
// 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);
// Use semi-transparent black (c0000000) for x and y major surface grid lines. Use
// dotted style for x and y minor surface grid lines.
int majorGridColor = unchecked((int)0xc0000000);
int minorGridColor = c.dashLineColor(majorGridColor, Chart.DotLine);
c.setSurfaceAxisGrid(majorGridColor, majorGridColor, minorGridColor, minorGridColor);
// Add XY projection
c.addXYProjection();
// Set contour lines to semi-transparent white (0x7fffffff)
c.setContourColor(0x7fffffff);
// Add a color axis (the legend) in which the left center is anchored at (620, 250). Set
// the length to 200 pixels and the labels on the right side.
c.setColorAxis(620, 250, Chart.Left, 200, Chart.Right);
// Set the x, y and z axis titles using 12 pt 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*>X: {x|2}<*br*>Y: {y|2}<*br*>Z: {z|2}'");
}
}
}
Imports System
Imports Microsoft.VisualBasic
Imports ChartDirector
Public Class surfaceprojection
Implements DemoModule
'Name of demo module
Public Function getName() As String Implements DemoModule.getName
Return "Surface Projection"
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 = {0, 1, 2, 3, 4, 5, 6, 7, 8}
Dim dataY() As Double = {0, 1, 2, 3, 4, 5, 6, 7, 8}
' Use random numbers for the z values on the XY grid
Dim r As RanSeries = New RanSeries(11)
Dim dataZ() As Double = r.get2DSeries(UBound(dataX) + 1, UBound(dataY) + 1, 0.1, 1.9)
' Create a SurfaceChart object of size 680 x 580 pixels
Dim c As SurfaceChart = New SurfaceChart(680, 580)
' Set the center of the plot region at (310, 280), and set width x depth x height to 320 x
' 320 x 240 pixels
c.setPlotRegion(310, 280, 320, 320, 240)
' Set the elevation and rotation angles to 30 and 45 degrees
c.setViewAngle(30, 45)
' 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)
' Use semi-transparent black (c0000000) for x and y major surface grid lines. Use dotted
' style for x and y minor surface grid lines.
Dim majorGridColor As Integer = &Hc0000000
Dim minorGridColor As Integer = c.dashLineColor(majorGridColor, Chart.DotLine)
c.setSurfaceAxisGrid(majorGridColor, majorGridColor, minorGridColor, minorGridColor)
' Add XY projection
c.addXYProjection()
' Set contour lines to semi-transparent white (0x7fffffff)
c.setContourColor(&H7fffffff)
' Add a color axis (the legend) in which the left center is anchored at (620, 250). Set the
' length to 200 pixels and the labels on the right side.
c.setColorAxis(620, 250, Chart.Left, 200, Chart.Right)
' Set the x, y and z axis titles using 12 pt 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*>X: {x|2}<*br*>Y: {y|2}<*br*>Z: {z|2}'")
End Sub
End Class
using System;
using ChartDirector;
namespace CSharpWPFCharts
{
public class surfaceprojection : DemoModule
{
//Name of demo module
public string getName() { return "Surface Projection"; }
//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 = {0, 1, 2, 3, 4, 5, 6, 7, 8};
double[] dataY = {0, 1, 2, 3, 4, 5, 6, 7, 8};
// Use random numbers for the z values on the XY grid
RanSeries r = new RanSeries(11);
double[] dataZ = r.get2DSeries(dataX.Length, dataY.Length, 0.1, 1.9);
// Create a SurfaceChart object of size 680 x 580 pixels
SurfaceChart c = new SurfaceChart(680, 580);
// Set the center of the plot region at (310, 280), and set width x depth x height to
// 320 x 320 x 240 pixels
c.setPlotRegion(310, 280, 320, 320, 240);
// Set the elevation and rotation angles to 30 and 45 degrees
c.setViewAngle(30, 45);
// 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);
// Use semi-transparent black (c0000000) for x and y major surface grid lines. Use
// dotted style for x and y minor surface grid lines.
int majorGridColor = unchecked((int)0xc0000000);
int minorGridColor = c.dashLineColor(majorGridColor, Chart.DotLine);
c.setSurfaceAxisGrid(majorGridColor, majorGridColor, minorGridColor, minorGridColor);
// Add XY projection
c.addXYProjection();
// Set contour lines to semi-transparent white (0x7fffffff)
c.setContourColor(0x7fffffff);
// Add a color axis (the legend) in which the left center is anchored at (620, 250). Set
// the length to 200 pixels and the labels on the right side.
c.setColorAxis(620, 250, Chart.Left, 200, Chart.Right);
// Set the x, y and z axis titles using 12 pt 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*>X: {x|2}<*br*>Y: {y|2}<*br*>Z: {z|2}'");
}
}
}
<%@ 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 = {0, 1, 2, 3, 4, 5, 6, 7, 8};
double[] dataY = {0, 1, 2, 3, 4, 5, 6, 7, 8};
// Use random numbers for the z values on the XY grid
RanSeries r = new RanSeries(11);
double[] dataZ = r.get2DSeries(dataX.Length, dataY.Length, 0.1, 1.9);
// Create a SurfaceChart object of size 680 x 580 pixels
SurfaceChart c = new SurfaceChart(680, 580);
// Set the center of the plot region at (310, 280), and set width x depth x height to 320 x 320
// x 240 pixels
c.setPlotRegion(310, 280, 320, 320, 240);
// Set the elevation and rotation angles to 30 and 45 degrees
c.setViewAngle(30, 45);
// 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);
// Use semi-transparent black (c0000000) for x and y major surface grid lines. Use dotted style
// for x and y minor surface grid lines.
int majorGridColor = unchecked((int)0xc0000000);
int minorGridColor = c.dashLineColor(majorGridColor, Chart.DotLine);
c.setSurfaceAxisGrid(majorGridColor, majorGridColor, minorGridColor, minorGridColor);
// Add XY projection
c.addXYProjection();
// Set contour lines to semi-transparent white (0x7fffffff)
c.setContourColor(0x7fffffff);
// Add a color axis (the legend) in which the left center is anchored at (620, 250). Set the
// length to 200 pixels and the labels on the right side.
c.setColorAxis(620, 250, Chart.Left, 200, Chart.Right);
// Set the x, y and z axis titles using 12 pt 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>
<%@ 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 = {0, 1, 2, 3, 4, 5, 6, 7, 8}
Dim dataY() As Double = {0, 1, 2, 3, 4, 5, 6, 7, 8}
' Use random numbers for the z values on the XY grid
Dim r As RanSeries = New RanSeries(11)
Dim dataZ() As Double = r.get2DSeries(UBound(dataX) + 1, UBound(dataY) + 1, 0.1, 1.9)
' Create a SurfaceChart object of size 680 x 580 pixels
Dim c As SurfaceChart = New SurfaceChart(680, 580)
' Set the center of the plot region at (310, 280), and set width x depth x height to 320 x 320 x
' 240 pixels
c.setPlotRegion(310, 280, 320, 320, 240)
' Set the elevation and rotation angles to 30 and 45 degrees
c.setViewAngle(30, 45)
' 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)
' Use semi-transparent black (c0000000) for x and y major surface grid lines. Use dotted style
' for x and y minor surface grid lines.
Dim majorGridColor As Integer = &Hc0000000
Dim minorGridColor As Integer = c.dashLineColor(majorGridColor, Chart.DotLine)
c.setSurfaceAxisGrid(majorGridColor, majorGridColor, minorGridColor, minorGridColor)
' Add XY projection
c.addXYProjection()
' Set contour lines to semi-transparent white (0x7fffffff)
c.setContourColor(&H7fffffff)
' Add a color axis (the legend) in which the left center is anchored at (620, 250). Set the
' length to 200 pixels and the labels on the right side.
c.setColorAxis(620, 250, Chart.Left, 200, Chart.Right)
' Set the x, y and z axis titles using 12 pt 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>
using System;
using System.Web.Mvc;
using ChartDirector;
namespace NetMvcCharts.Controllers
{
public class SurfaceprojectionController : Controller
{
//
// Default Action
//
public ActionResult Index()
{
ViewBag.Title = "Surface Projection";
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 = {0, 1, 2, 3, 4, 5, 6, 7, 8};
double[] dataY = {0, 1, 2, 3, 4, 5, 6, 7, 8};
// Use random numbers for the z values on the XY grid
RanSeries r = new RanSeries(11);
double[] dataZ = r.get2DSeries(dataX.Length, dataY.Length, 0.1, 1.9);
// Create a SurfaceChart object of size 680 x 580 pixels
SurfaceChart c = new SurfaceChart(680, 580);
// Set the center of the plot region at (310, 280), and set width x depth x height to 320 x
// 320 x 240 pixels
c.setPlotRegion(310, 280, 320, 320, 240);
// Set the elevation and rotation angles to 30 and 45 degrees
c.setViewAngle(30, 45);
// 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);
// Use semi-transparent black (c0000000) for x and y major surface grid lines. Use dotted
// style for x and y minor surface grid lines.
int majorGridColor = unchecked((int)0xc0000000);
int minorGridColor = c.dashLineColor(majorGridColor, Chart.DotLine);
c.setSurfaceAxisGrid(majorGridColor, majorGridColor, minorGridColor, minorGridColor);
// Add XY projection
c.addXYProjection();
// Set contour lines to semi-transparent white (0x7fffffff)
c.setContourColor(0x7fffffff);
// Add a color axis (the legend) in which the left center is anchored at (620, 250). Set the
// length to 200 pixels and the labels on the right side.
c.setColorAxis(620, 250, Chart.Left, 200, Chart.Right);
// Set the x, y and z axis titles using 12 pt 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);
}
}
}
@{ 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>