Gallery
Map Shape Info
<%@ Page Language="C#" Description="dotnetCHARTING Component" %>
<%@ Register TagPrefix="dotnet" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<%@ Import Namespace="dotnetCHARTING.Mapping" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Sample</title>
<script runat="server">
// Demonstrates adding annotations to selected shapes showing more details.
void Page_Load(Object sender, EventArgs e)
{
// Setup the chart.
Chart.Type = ChartType.Map;
Chart.Size = "650x400";
Chart.Title = "Click on a state to see more information";
Chart.TempDirectory = "temp";
Chart.Debug = true;
Chart.ChartArea.Background.ShadingEffectMode = ShadingEffectMode.Background2;
Chart.LegendBox.Visible = false;
Chart.ChartArea.Background.Color = Color.FromArgb(182,222,255);
// Style the title box.
Chart.TitleBox.Position = TitleBoxPosition.Full;
Chart.TitleBox.Label.Color = Color.DarkBlue;
Chart.TitleBox.Background.Color = Color.LightSkyBlue;
Chart.TitleBox.CornerTopLeft = Chart.TitleBox.CornerTopRight = BoxCorner.Round;
// Create a layer for the map.
MapLayer layer = MapDataEngine.LoadLayer("../../images/MapFiles/primusa.shp");
layer.DefaultShape.Background.Color = Color.FromArgb(240, 240, 240);
// Make each shape clickable so it's state abbreviation can be passed to this page.
layer.DefaultShape.Hotspot.URL = "?id=%STATE_ABBR";
// Get the state abbreviation from the query string.
string abbr = "";
if (Page.Request.QueryString.Count > 0)
abbr = Page.Request.QueryString["id"].ToString();
// If the abbreviation was passed, add an annotation showing more detail for that state.
if (abbr.Length > 0)
{
// Create the annotation.
Annotation an = new Annotation("Name: <Block>%State_Name<row>Population: <Block>%Population<row>Males - Females<br>%Males - %Females<Chart:Pie values='%Males,%Females'>");
an.DynamicSize = false;
an.DefaultCorner = BoxCorner.Round;
an.Background.ShadingEffectMode = ShadingEffectMode.Background2;
an.Background.Color = Color.DeepSkyBlue;
// Find the shape to add it to.
foreach (Shape shape in layer.Shapes)
{
if ((string)shape["state_abbr"] == abbr)
{
shape.Annotation = an;
break;
}
}
}
// Add the states layer to the chart.
Chart.Mapping.MapLayerCollection.Add(layer);
}
</script>
</head>
<body>
<div style="text-align: center">
<dotnet:Chart ID="Chart" runat="server">
</dotnet:Chart>
</div>
</body>
</html>
<%@ Page Language="vb" Description="dotnetCHARTING Component" %>
<%@ Register TagPrefix="dotnet" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<%@ Import Namespace="dotnetCHARTING.Mapping" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Sample</title>
<script runat="server">
' Demonstrates adding annotations to selected shapes showing more details.
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Setup the chart.
Chart.Type = ChartType.Map
Chart.Size = "650x400"
Chart.Title = "Click on a state to see more information"
Chart.TempDirectory = "temp"
Chart.Debug = True
Chart.ChartArea.Background.ShadingEffectMode = ShadingEffectMode.Background2
Chart.LegendBox.Visible = False
Chart.ChartArea.Background.Color = Color.FromArgb(182,222,255)
' Style the title box.
Chart.TitleBox.Position = TitleBoxPosition.Full
Chart.TitleBox.Label.Color = Color.DarkBlue
Chart.TitleBox.Background.Color = Color.LightSkyBlue
Chart.TitleBox.CornerTopRight = BoxCorner.Round
Chart.TitleBox.CornerTopLeft = Chart.TitleBox.CornerTopRight
' Create a layer for the map.
Dim layer As MapLayer = MapDataEngine.LoadLayer("../../images/MapFiles/primusa.shp")
layer.DefaultShape.Background.Color = Color.FromArgb(240, 240, 240)
' Make each shape clickable so it's state abbreviation can be passed to this page.
layer.DefaultShape.Hotspot.URL = "?id=%STATE_ABBR"
' Get the state abbreviation from the query string.
Dim abbr As String = ""
If Page.Request.QueryString.Count > 0 Then
abbr = Page.Request.QueryString("id").ToString()
End If
' If the abbreviation was passed, add an annotation showing more detail for that state.
If abbr.Length > 0 Then
' Create the annotation.
Dim an As Annotation = New Annotation("Name: <Block>%State_Name<row>Population: <Block>%Population<row>Males - Females<br>%Males - %Females<Chart:Pie values='%Males,%Females'>")
an.DynamicSize = False
an.DefaultCorner = BoxCorner.Round
an.Background.ShadingEffectMode = ShadingEffectMode.Background2
an.Background.Color = Color.DeepSkyBlue
' Find the shape to add it to.
For Each shape As Shape In layer.Shapes
If CStr(shape("state_abbr")) = abbr Then
shape.Annotation = an
Exit For
End If
Next shape
End If
' Add the states layer to the chart.
Chart.Mapping.MapLayerCollection.Add(layer)
End Sub
</script>
</head>
<body>
<div style="text-align: center">
<dotnet:Chart ID="Chart" runat="server">
</dotnet:Chart>
</div>
</body>
</html>
- Sample FilenameMapShapeInfo.aspx
- Version5.3
- Uses DatabaseNo