Gallery
Surface Image Heatmap
<%@ Page Language="C#" Description="dotnetCHARTING Component" %>
<%@ Register TagPrefix="dnc" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<%@ Import Namespace="dotnetCHARTING.Mapping" %>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Demonstrates a 2D heatmap with transparent colors overlaying an image.
Chart.Size = "930x524";
Chart.TempDirectory = "temp";
Chart.Debug = true;
Chart.Use3D = false;
Chart.Type = ChartType.Surface;
Chart.LegendBox.Visible = false;
Chart.MarginTop = 60;
Chart.DefaultSeries.Type = SeriesTypeSurface.Surface;
Chart.DefaultElement.Transparency = 40;
Chart.DefaultSeries.InterpolationFillFactor = 5;
Chart.DefaultSeries.Line.Transparency = 100;
SeriesCollection mySC = getRData();
Chart.SmartPalette = mySC[0].GetSmartPalette(ElementValue.ZValue, Color.Blue, Color.Transparent, Color.Transparent,Color.Yellow, Color.Orange, Color.Crimson);
Annotation an = new Annotation(getSwatch(780, Chart.SmartPalette, 10, true));
an.Header.Label.Text = "<Chart:Scale min='" + Chart.SmartPalette.GetScaleRange("*").ValueLow + "' max='" + Chart.SmartPalette.GetScaleRange("*").ValueHigh + "' width='890' >";
an.ClearColors();
Chart.Annotations.Add(an);
an.Position = new Point(25, 10);
an.DynamicSize = false;
// Add the random data.
Chart.SeriesCollection.Add(mySC);
mySC[0].Line.Transparency = 80;
Chart.YAxis.AlternateGridBackground.Color = Color.Empty;
Chart.YAxis.ZeroTick = null;
Chart.XAxis.ZeroTick = null;
Chart.ChartArea.Background = new Background(getMapImage());
Chart.ChartArea.Background.Mode = BackgroundMode.ImageStretch;
}
SeriesCollection getRData()
{
int size = 20;
double[][] zVals = new double[size][];
double[] xVals = new double[size];
double[] yVals = new double[size];
// Series s = new Series();
for (int i = 0; i < size; i++)
{
zVals[i] = new double[size];
for (int j = 0; j < size; j++)
{
double x = (double)(-2 + i * .16);
double y = (double)(-2 + j * .16);
xVals[i] = x;
yVals[j] = y;
x += 5;
zVals[i][j] = (Math.Sin(x * 3.2) + Math.Cos(y * 2) + Math.Sin(x * 1.2) + Math.Sin(y * 1.2));
}
}
SeriesCollection SC = new SeriesCollection();
Series s = Series.FromSurfaceData("", xVals, yVals, zVals);
SC.Add(s);
return SC;
}
string getMapImage()
{
Chart c = new Chart();
c.Size = "630x320";
c.Type = ChartType.Map;
c.Margin = "-30";
//c.MarginRight = -20;
//c.MarginTop = -30;
//c.MarginBottom = -20;
c.TempDirectory = "temp";
c.Mapping.MapLayerCollection.Add("../../Images/MapFiles/primusa.shp");
//c.Mapping.ZoomPercentage = 120;
return c.FileManager.SaveImage();
}
string getSwatch(int width, SmartPalette sp, int divisions, bool withValues)
{
// Get Maximum Value of the smart palette range
double max = (double)sp.GetScaleRange("*").ValueHigh;
double min = (double)sp.GetScaleRange("*").ValueLow;
string swatch = "", spacers = "";
double step = (max - min) / divisions;
// Width of each division.
int boxWidth = width / divisions;
// Generate swatch string for each division.
for (int i = 0; i <= divisions; i++)
{
spacers += "<Chart:Spacer size='" + boxWidth + "x1'>";
// Get the color of the current division.
string color = getHTMLColor(sp.GetValueColor("", min + (i * (step))));
if (withValues)
swatch += "<block hAlignment='Center' bgColor='" + color + "'>" + Math.Round((min + (i * (step))), 1);
else
swatch += "<block bgColor='" + color + "' fColor='" + color + "'>_";
}
//return the swatch string.
return spacers + "<row>" + swatch;
}
string getHTMLColor(Color c)
{
return "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Sample</title>
</head>
<style type="text/css">
div, p
{
font-family: Arial, Helvetica, sans-serif;
font-size: x-small;
}
</style>
<body>
<div align="center">
<dnc:Chart ID="Chart" runat="server" />
</div>
</body>
</html>
<%@ Page Language="vb" Description="dotnetCHARTING Component" %>
<%@ Register TagPrefix="dnc" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<%@ Import Namespace="dotnetCHARTING.Mapping" %>
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Demonstrates a 2D heatmap with transparent colors overlaying an image.
Chart.Size = "930x524"
Chart.TempDirectory = "temp"
Chart.Debug = True
Chart.Use3D = False
Chart.Type = ChartType.Surface
Chart.LegendBox.Visible = False
Chart.MarginTop = 60
Chart.DefaultSeries.Type = SeriesTypeSurface.Surface
Chart.DefaultElement.Transparency = 40
Chart.DefaultSeries.InterpolationFillFactor = 5
Chart.DefaultSeries.Line.Transparency = 100
Dim mySC As SeriesCollection = getRData()
Chart.SmartPalette = mySC(0).GetSmartPalette(ElementValue.ZValue, Color.Blue, Color.Transparent, Color.Transparent,Color.Yellow, Color.Orange, Color.Crimson)
Dim an As Annotation = New Annotation(getSwatch(780, Chart.SmartPalette, 10, True))
an.Header.Label.Text = "<Chart:Scale min='" & Chart.SmartPalette.GetScaleRange("*").ValueLow & "' max='" & Chart.SmartPalette.GetScaleRange("*").ValueHigh & "' width='890' >"
an.ClearColors()
Chart.Annotations.Add(an)
an.Position = New Point(25, 10)
an.DynamicSize = False
' Add the random data.
Chart.SeriesCollection.Add(mySC)
mySC(0).Line.Transparency = 80
Chart.YAxis.AlternateGridBackground.Color = Color.Empty
Chart.YAxis.ZeroTick = Nothing
Chart.XAxis.ZeroTick = Nothing
Chart.ChartArea.Background = New Background(getMapImage())
Chart.ChartArea.Background.Mode = BackgroundMode.ImageStretch
End Sub
Function getRData() As SeriesCollection
Dim size As Integer = 20
Dim zVals As Double()() = New Double(size - 1)(){}
Dim xVals As Double() = New Double(size - 1){}
Dim yVals As Double() = New Double(size - 1){}
' Series s = new Series();
For i As Integer = 0 To size - 1
zVals(i) = New Double(size - 1){}
For j As Integer = 0 To size - 1
Dim x As Double = CDbl(-2 + i *.16)
Dim y As Double = CDbl(-2 + j *.16)
xVals(i) = x
yVals(j) = y
x += 5
zVals(i)(j) = (Math.Sin(x * 3.2) + Math.Cos(y * 2) + Math.Sin(x * 1.2) + Math.Sin(y * 1.2))
Next j
Next i
Dim SC As SeriesCollection = New SeriesCollection()
Dim s As Series = Series.FromSurfaceData("", xVals, yVals, zVals)
SC.Add(s)
Return SC
End Function
Function getMapImage() As String
Dim c As Chart = New Chart()
c.Size = "630x320"
c.Type = ChartType.Map
c.Margin = "-30"
'c.MarginRight = -20;
'c.MarginTop = -30;
'c.MarginBottom = -20;
c.TempDirectory = "temp"
c.Mapping.MapLayerCollection.Add("../../Images/MapFiles/primusa.shp")
'c.Mapping.ZoomPercentage = 120;
Return c.FileManager.SaveImage()
End Function
Function getSwatch(ByVal width As Integer, ByVal sp As SmartPalette, ByVal divisions As Integer, ByVal withValues As Boolean) As String
' Get Maximum Value of the smart palette range
Dim max As Double = CDbl(sp.GetScaleRange("*").ValueHigh)
Dim min As Double = CDbl(sp.GetScaleRange("*").ValueLow)
Dim swatch As String = "", spacers As String = ""
Dim [step] As Double = (max - min) / divisions
' Width of each division.
Dim boxWidth As Integer = width / divisions
' Generate swatch string for each division.
For i As Integer = 0 To divisions
spacers &= "<Chart:Spacer size='" & boxWidth & "x1'>"
' Get the color of the current division.
Dim color As String = getHTMLColor(sp.GetValueColor("", min + (i * ([step]))))
If withValues Then
swatch &= "<block hAlignment='Center' bgColor='" & color & "'>" & Math.Round((min + (i * ([step]))), 1)
Else
swatch &= "<block bgColor='" & color & "' fColor='" & color & "'>_"
End If
Next i
'return the swatch string.
Return spacers & "<row>" & swatch
End Function
Function getHTMLColor(ByVal c As Color) As String
Return "#" & c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2")
End Function
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Sample</title>
</head>
<style type="text/css">
div, p
{
font-family: Arial, Helvetica, sans-serif;
font-size: x-small;
}
</style>
<body>
<div align="center">
<dnc:Chart ID="Chart" runat="server" />
</div>
</body>
</html>
- Sample FilenameSurfaceImageHeatmap.aspx
- Version6.2
- Uses DatabaseNo