Gallery
Tree Map Interactive
<%@ Page Language="C#" Description="dotnetCHARTING Component" %>
<%@ Register TagPrefix="dnc" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING" %>
<%@ Import Namespace="System.Drawing" %>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Demonstrates an interactive TreeMap chart that shows treemap detail for series..
Chart.Size = "600x450";
//Chart.Title = ".netCHARTING Sample";
Chart.TempDirectory = "temp";
Chart.Debug = true;
Chart.Type = ChartType.TreeMap;
Chart.LegendBox.Visible = false;
// Distance between series boxes
Chart.ChartArea.Padding = 6;
//Element labels and tooltip
Chart.DefaultElement.ToolTip = "%Name";
Chart.DefaultElement.ShowValue = true;
Chart.DefaultElement.SmartLabel.DynamicDisplay = false;
Chart.DefaultElement.SmartLabel.LineAlignment = StringAlignment.Center;
// Range SmartColors
Chart.SmartPalette.Add("*", new SmartColor(Color.Red, Color.Yellow, new ScaleRange(0, 20)));
Chart.SmartPalette.Add("*", new SmartColor(Color.Yellow, Color.YellowGreen, new ScaleRange(20, 50)));
// Style the series box header.
Chart.DefaultSeries.Box = new Box();
Chart.DefaultSeries.Box.Header.Label.Text = "%Name";
Chart.DefaultSeries.Box.Header.Label.Alignment = StringAlignment.Near;
// Chart.DefaultSeries.Box.Header.Label.Color = Color.Blue;
Chart.DefaultSeries.Box.Header.Label.Font = new Font("Arial", 8, FontStyle.Underline);
Chart.DefaultSeries.Box.Header.Label.Hotspot.URL = "?sID=%Name";
Chart.DefaultSeries.Box.Header.Label.Hotspot.ToolTip = "Show Detail";
Chart.DefaultSeries.Box.Header.Offset = new Point(0, -3);
Chart.DefaultBox.Header.VerticalAlignment = EdgeAlignment.Edge;
Chart.DefaultBox.Header.StartAlignment = EdgeAlignment.Inside;
Chart.DefaultBox.Header.EndAlignment = EdgeAlignment.Inside;
Chart.DefaultBox.Header.StartCap = BoxCapStyle.Box;
Chart.DefaultBox.Header.EndCap = BoxCapStyle.Triangle;
// Style the titlebox and add the swatch to the header.
Chart.TitleBox.Position = TitleBoxPosition.Full;
Chart.TitleBox.Orientation = dotnetCHARTING.Orientation.Bottom;
BoxHeaderOptions titleHead = Chart.TitleBox.Header;
titleHead.Label.Text = getSwatch(358, Chart.SmartPalette, 20, true);
titleHead.Label.Alignment = StringAlignment.Far;
titleHead.VerticalAlignment = EdgeAlignment.Outside;
titleHead.Offset = new Point(-14, 392);
titleHead.StartCap = BoxCapStyle.Triangle;
titleHead.EndCap = BoxCapStyle.Box;
Chart.ChartArea.Padding = 14;
// *DYNAMIC DATA NOTE*
// This sample uses random data to populate the chart. To populate
// a chart with database data see the following resources:
// - Use the getLiveData() method using the dataEngine to query a database.
// - Help File > Getting Started > Data Tutorials
// - DataEngine Class in the help file
// - Sample: features/DataEngine.aspx
SeriesCollection mySC = getRandomData();
bool addAll = true;
if (Page.Request.QueryString.Count > 0)
{
string query = Page.Request.QueryString["sID"];
if (query != null && query.Length > 0)
{
foreach (Series s in mySC)
{
if (s.Name == query)
{
Chart.SeriesCollection.Add(s);
Chart.DefaultElement.SmartLabel.Text = "%Name\n%YValue";
addBackButton();
addAll = false;
break;
}
}
}
}
// If it's not showing details of a series, add all the random data.
if(addAll)
Chart.SeriesCollection.Add(mySC);
}
void addBackButton()
{
Annotation an = new Annotation("< Show All");
an.Size = new Size(75, 0);
an.DefaultCorner = BoxCorner.Cut;
an.Background.Color = Color.White;
an.Position = new Point(5, 2);
an.URL = "?";
Chart.Annotations.Add(an);
}
string getSwatch(int width, SmartPalette sp, int divisions, bool withValues)
{
// Get Maximum Value of the smart palette range
double max = (double)sp.GetScaleRange("*").ValueHigh;
string swatch = "", spacers = "";
// 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("", (i * (max / divisions))));
if (withValues)
swatch += "<block hAlignment='Center' bgColor='" + color + "'>" + (int)(i * (max / divisions));
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");
}
SeriesCollection getRandomData()
{
Random myR = new Random(1);
SeriesCollection SC = new SeriesCollection();
for (int a = 1; a < 10; a++)
{
Series s = new Series("Series " + a.ToString());
int count = 5 + myR.Next(40);
for (int b = 1; b < count; b++)
{
Element e = new Element("Element " + b.ToString());
e.YValue = 5 + myR.Next(45);
s.Elements.Add(e);
}
SC.Add(s);
}
return SC;
}
SeriesCollection getLiveData()
{
DataEngine de = new DataEngine(ConfigurationManager.AppSettings["DNCConnectionString"]);
de.ChartObject = Chart; // Necessary to view any errors the dataEngine may throw.
de.SqlStatement = "SELECT XAxisColumn, YAxisColumn FROM ....";
return de.GetSeries();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Sample</title>
</head>
<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" %>
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Demonstrates an interactive TreeMap chart that shows treemap detail for series..
Chart.Size = "600x450"
'Chart.Title = ".netCHARTING Sample";
Chart.TempDirectory = "temp"
Chart.Debug = True
Chart.Type = ChartType.TreeMap
Chart.LegendBox.Visible = False
' Distance between series boxes
Chart.ChartArea.Padding = 6
'Element labels and tooltip
Chart.DefaultElement.ToolTip = "%Name"
Chart.DefaultElement.ShowValue = True
Chart.DefaultElement.SmartLabel.DynamicDisplay = False
Chart.DefaultElement.SmartLabel.LineAlignment = StringAlignment.Center
' Range SmartColors
Chart.SmartPalette.Add("*", New SmartColor(Color.Red, Color.Yellow, New ScaleRange(0, 20)))
Chart.SmartPalette.Add("*", New SmartColor(Color.Yellow, Color.YellowGreen, New ScaleRange(20, 50)))
' Style the series box header.
Chart.DefaultSeries.Box = New Box()
Chart.DefaultSeries.Box.Header.Label.Text = "%Name"
Chart.DefaultSeries.Box.Header.Label.Alignment = StringAlignment.Near
' Chart.DefaultSeries.Box.Header.Label.Color = Color.Blue;
Chart.DefaultSeries.Box.Header.Label.Font = New Font("Arial", 8, FontStyle.Underline)
Chart.DefaultSeries.Box.Header.Label.Hotspot.URL = "?sID=%Name"
Chart.DefaultSeries.Box.Header.Label.Hotspot.ToolTip = "Show Detail"
Chart.DefaultSeries.Box.Header.Offset = New Point(0, -3)
Chart.DefaultBox.Header.VerticalAlignment = EdgeAlignment.Edge
Chart.DefaultBox.Header.StartAlignment = EdgeAlignment.Inside
Chart.DefaultBox.Header.EndAlignment = EdgeAlignment.Inside
Chart.DefaultBox.Header.StartCap = BoxCapStyle.Box
Chart.DefaultBox.Header.EndCap = BoxCapStyle.Triangle
' Style the titlebox and add the swatch to the header.
Chart.TitleBox.Position = TitleBoxPosition.Full
Chart.TitleBox.Orientation = dotnetCHARTING.Orientation.Bottom
Dim titleHead As BoxHeaderOptions = Chart.TitleBox.Header
titleHead.Label.Text = getSwatch(358, Chart.SmartPalette, 20, True)
titleHead.Label.Alignment = StringAlignment.Far
titleHead.VerticalAlignment = EdgeAlignment.Outside
titleHead.Offset = New Point(-14, 392)
titleHead.StartCap = BoxCapStyle.Triangle
titleHead.EndCap = BoxCapStyle.Box
Chart.ChartArea.Padding = 14
' *DYNAMIC DATA NOTE*
' This sample uses random data to populate the chart. To populate
' a chart with database data see the following resources:
' - Use the getLiveData() method using the dataEngine to query a database.
' - Help File > Getting Started > Data Tutorials
' - DataEngine Class in the help file
' - Sample: features/DataEngine.aspx
Dim mySC As SeriesCollection = getRandomData()
Dim addAll As Boolean = True
If Page.Request.QueryString.Count > 0 Then
Dim query As String = Page.Request.QueryString("sID")
If Not query Is Nothing AndAlso query.Length > 0 Then
For Each s As Series In mySC
If s.Name = query Then
Chart.SeriesCollection.Add(s)
Chart.DefaultElement.SmartLabel.Text = "%Name" & Constants.vbLf & "%YValue"
addBackButton()
addAll = False
Exit For
End If
Next s
End If
End If
' If it's not showing details of a series, add all the random data.
If addAll Then
Chart.SeriesCollection.Add(mySC)
End If
End Sub
Sub addBackButton()
Dim an As Annotation = New Annotation("< Show All")
an.Size = New Size(75, 0)
an.DefaultCorner = BoxCorner.Cut
an.Background.Color = Color.White
an.Position = New Point(5, 2)
an.URL = "?"
Chart.Annotations.Add(an)
End Sub
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 swatch As String = "", spacers As String = ""
' 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("", (i * (max / divisions))))
If withValues Then
swatch &= "<block hAlignment='Center' bgColor='" & color & "'>" & CInt(Fix(i * (max / divisions)))
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
Function getRandomData() As SeriesCollection
Dim myR As Random = New Random(1)
Dim SC As SeriesCollection = New SeriesCollection()
For a As Integer = 1 To 9
Dim s As Series = New Series("Series " & a.ToString())
Dim count As Integer = 5 + myR.Next(40)
For b As Integer = 1 To count - 1
Dim e As Element = New Element("Element " & b.ToString())
e.YValue = 5 + myR.Next(45)
s.Elements.Add(e)
Next b
SC.Add(s)
Next a
Return SC
End Function
Function getLiveData() As SeriesCollection
Dim de As DataEngine = New DataEngine(ConfigurationManager.AppSettings("DNCConnectionString"))
de.ChartObject = Chart ' Necessary to view any errors the dataEngine may throw.
de.SqlStatement = "SELECT XAxisColumn, YAxisColumn FROM ...."
Return de.GetSeries()
End Function
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Sample</title>
</head>
<body>
<div align="center">
<dnc:Chart ID="Chart" runat="server" />
</div>
</body>
</html>
- Sample FilenameTreeMapInteractive.aspx
- Version6.1
- Uses DatabaseNo