Gallery
Org Levels 2
<%@ 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 using the Series.Trim method to figure out the organizational level each node is on.
Chart.Size = "900x300";
Chart.TempDirectory = "temp";
Chart.Type = ChartType.Organizational;
Chart.Debug = true;
Chart.Palette = new Color[] { Color.FromArgb(49, 255, 49), Color.FromArgb(255, 255, 0), Color.FromArgb(255, 99, 49), Color.FromArgb(0, 156, 255), Color.Orange };
Chart.LegendBox.Background.Color = Color.FromArgb(240, 240, 240);
// Set styling defaults.
Chart.ChartArea.ClearColors();
Chart.DefaultSeries.Line.Color = Color.Gray;
Chart.DefaultSeries.Line.Width = 3;
Chart.DefaultSeries.LegendEntry.Visible = false;
// Style the default annotation.
Chart.DefaultElement.Annotation = new Annotation();
Chart.DefaultElement.Annotation.Padding = 5;
Chart.DefaultElement.Annotation.Size = new Size(75, 30);
Chart.DefaultElement.Annotation.Background.ShadingEffectMode = ShadingEffectMode.Background2;
// Get Data
SeriesCollection mySC = getLiveData();
// Trim the data to get organizational levels and other attributes.
Series result = mySC[0].Trim(20);
foreach (Element el in result.Elements)
{
// Each node takes a color set based on the organizational level.
if (el.CustomAttributes["OrganizationalLevel"] != null)
{
if (el.Annotation == null) el.Annotation = new Annotation();
el.Annotation.Background.Color = Chart.Palette[((int)el.CustomAttributes["OrganizationalLevel"]) - 1];
}
}
// Create legendbox
Chart.LegendBox.Visible = true;
Chart.LegendBox.Position = LegendBoxPosition.Middle;
Chart.LegendBox.Padding = 5;
for (int i = 0; i < 5; i++)
Chart.LegendBox.ExtraEntries.Add(new LegendEntry("Level " + (i + 1), "", Chart.Palette[i]));
// Add the data
Chart.SeriesCollection.Add(result);
}
SeriesCollection getLiveData()
{
// Obtain series data from the database. Note this was created by adding PID (parentid)
// to an existing table only, then populating the parentid based on the hiearchy in place.
DataEngine de = new DataEngine(ConfigurationManager.AppSettings["DNCConnectionString"]);
de.SqlStatement = @"SELECT * FROM Employees";
de.DataFields = "InstanceID=ID,InstanceParentID=PID,Name=Name,office,Department,Email,Phone,Picture";
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 using the Series.Trim method to figure out the organizational level each node is on.
Chart.Size = "900x300"
Chart.TempDirectory = "temp"
Chart.Type = ChartType.Organizational
Chart.Debug = True
Chart.Palette = New Color() { Color.FromArgb(49, 255, 49), Color.FromArgb(255, 255, 0), Color.FromArgb(255, 99, 49), Color.FromArgb(0, 156, 255), Color.Orange }
Chart.LegendBox.Background.Color = Color.FromArgb(240, 240, 240)
' Set styling defaults.
Chart.ChartArea.ClearColors()
Chart.DefaultSeries.Line.Color = Color.Gray
Chart.DefaultSeries.Line.Width = 3
Chart.DefaultSeries.LegendEntry.Visible = False
' Style the default annotation.
Chart.DefaultElement.Annotation = New Annotation()
Chart.DefaultElement.Annotation.Padding = 5
Chart.DefaultElement.Annotation.Size = New Size(75, 30)
Chart.DefaultElement.Annotation.Background.ShadingEffectMode = ShadingEffectMode.Background2
' Get Data
Dim mySC As SeriesCollection = getLiveData()
' Trim the data to get organizational levels and other attributes.
Dim result As Series = mySC(0).Trim(20)
For Each el As Element In result.Elements
' Each node takes a color set based on the organizational level.
If Not el.CustomAttributes("OrganizationalLevel") Is Nothing Then
If el.Annotation Is Nothing Then
el.Annotation = New Annotation()
End If
el.Annotation.Background.Color = Chart.Palette((CInt(Fix(el.CustomAttributes("OrganizationalLevel")))) - 1)
End If
Next el
' Create legendbox
Chart.LegendBox.Visible = True
Chart.LegendBox.Position = LegendBoxPosition.Middle
Chart.LegendBox.Padding = 5
For i As Integer = 0 To 4
Chart.LegendBox.ExtraEntries.Add(New LegendEntry("Level " & (i + 1), "", Chart.Palette(i)))
Next i
' Add the data
Chart.SeriesCollection.Add(result)
End Sub
Function getLiveData() As SeriesCollection
' Obtain series data from the database. Note this was created by adding PID (parentid)
' to an existing table only, then populating the parentid based on the hiearchy in place.
Dim de As DataEngine = New DataEngine(ConfigurationManager.AppSettings("DNCConnectionString"))
de.SqlStatement = "SELECT * FROM Employees"
de.DataFields = "InstanceID=ID,InstanceParentID=PID,Name=Name,office,Department,Email,Phone,Picture"
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 FilenameOrgLevels2.aspx
- Version5.3
- Uses DatabaseYes