Gallery
Surface Date Grouping
<%@ 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" %>
<%@ Import Namespace="System.Collections.Generic" %>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Demonstrates creating a surface chart from live time based data.
// The time interval from the dropDown is used in getLiveData() to specify the DateGrouping.
// The x axis grouping is set to years below but any applicable grouping can be used.
Chart.Size = "850x550";
Chart.TempDirectory = "temp";
Chart.Debug = true;
Chart.Type = ChartType.Surface;
Chart.LegendBox.Visible = false;
Chart.ShowDateInTitle = false;
Chart.DefaultSeries.Background.Transparency = 20;
Chart.DefaultSeries.Type = SeriesTypeSurface.Contour;
Chart.MarginTop = 50;
Chart.YAxis.Label.Text = yGrouping.SelectedItem.Text;
Chart.XAxis.Label.Text = "Years";
if (surfaceXCheckBox.Checked)
{
Chart.Use3D = true;
Chart.DefaultSeries.Type = SeriesTypeSurface.SurfaceY;
Chart.DefaultElement.DrawToFloor = true;
Chart.View3D.AngleOfRotation = 45;
Chart.View3D.AngleOfTilt = 45;
}
SeriesCollection mySC = getLiveData();
if (mySC != null && mySC.Count > 0)
{
List<DateTime> xDates;
Series s = mySC[0].GetSurfaceData(TimeIntervalAdvanced.Years, out xDates);
for (int i = 0; i < xDates.Count; i++)
Chart.XAxis.ExtraTicks.Add(new AxisTick(i, xDates[i].Year.ToString()));
Chart.SeriesCollection.Add(s);
Chart.SmartPalette = s.GetSmartPalette(ElementValue.ZValue, Color.Blue, Color.Aqua, Color.LightGreen, Color.Yellow, Color.Orange, Color.Crimson);
Annotation an = new Annotation(getSwatch(510, Chart.SmartPalette, 10, false));
an.Header.Label.Text = "<Chart:Scale min='" + Chart.SmartPalette.GetScaleRange("*").ValueLow + "' max='" + Chart.SmartPalette.GetScaleRange("*").ValueHigh + "' width='590' >";
an.ClearColors();
Chart.Annotations.Add(an);
an.Position = new Point(135, 0);
an.DynamicSize = false;
}
}
SeriesCollection getLiveData()
{
DataEngine de = new DataEngine(ConfigurationManager.AppSettings["DNCConnectionString"]);
de.ChartObject = Chart; // Necessary to view any errors the dataEngine may throw.
de.SqlStatement = "SELECT dDate,downloads FROM downloads ";
de.DateGrouping = (TimeInterval)Enum.Parse(typeof(TimeInterval), yGrouping.SelectedItem.Text);
SeriesCollection sc = de.GetSeries();
return sc;
}
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>
<form id="form1" runat="server">
<div align="center">
<table>
<tr>
<td>
<asp:CheckBox ID="surfaceXCheckBox" Text="SurfaceX" runat="server" Checked="true"
AutoPostBack="true" />
<asp:DropDownList ID="yGrouping" runat="server" AutoPostBack="true">
<asp:ListItem>Days</asp:ListItem>
<asp:ListItem>Weeks</asp:ListItem>
<asp:ListItem Selected="True">Months</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<dnc:Chart ID="Chart" runat="server" />
</td>
</tr>
</table>
</div>
</form>
</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" %>
<%@ Import Namespace="System.Collections.Generic" %>
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Demonstrates creating a surface chart from live time based data.
' The time interval from the dropDown is used in getLiveData() to specify the DateGrouping.
' The x axis grouping is set to years below but any applicable grouping can be used.
Chart.Size = "850x550"
Chart.TempDirectory = "temp"
Chart.Debug = True
Chart.Type = ChartType.Surface
Chart.LegendBox.Visible = False
Chart.ShowDateInTitle = False
Chart.DefaultSeries.Background.Transparency = 20
Chart.DefaultSeries.Type = SeriesTypeSurface.Contour
Chart.MarginTop = 50
Chart.YAxis.Label.Text = yGrouping.SelectedItem.Text
Chart.XAxis.Label.Text = "Years"
If surfaceXCheckBox.Checked Then
Chart.Use3D = True
Chart.DefaultSeries.Type = SeriesTypeSurface.SurfaceY
Chart.DefaultElement.DrawToFloor = True
Chart.View3D.AngleOfRotation = 45
Chart.View3D.AngleOfTilt = 45
End If
Dim mySC As SeriesCollection = getLiveData()
If Not mySC Is Nothing AndAlso mySC.Count > 0 Then
Dim xDates As List(Of DateTime)
Dim s As Series = mySC(0).GetSurfaceData(TimeIntervalAdvanced.Years, xDates)
For i As Integer = 0 To xDates.Count - 1
Chart.XAxis.ExtraTicks.Add(New AxisTick(i, xDates(i).Year.ToString()))
Next i
Chart.SeriesCollection.Add(s)
Chart.SmartPalette = s.GetSmartPalette(ElementValue.ZValue, Color.Blue, Color.Aqua, Color.LightGreen, Color.Yellow, Color.Orange, Color.Crimson)
Dim an As Annotation = New Annotation(getSwatch(510, Chart.SmartPalette, 10, False))
an.Header.Label.Text = "<Chart:Scale min='" & Chart.SmartPalette.GetScaleRange("*").ValueLow & "' max='" & Chart.SmartPalette.GetScaleRange("*").ValueHigh & "' width='590' >"
an.ClearColors()
Chart.Annotations.Add(an)
an.Position = New Point(135, 0)
an.DynamicSize = False
End If
End Sub
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 dDate,downloads FROM downloads "
de.DateGrouping = CType(System.Enum.Parse(GetType(TimeInterval), yGrouping.SelectedItem.Text), TimeInterval)
Dim sc As SeriesCollection = de.GetSeries()
Return sc
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>
<form id="form1" runat="server">
<div align="center">
<table>
<tr>
<td>
<asp:CheckBox ID="surfaceXCheckBox" Text="SurfaceX" runat="server" Checked="true"
AutoPostBack="true" />
<asp:DropDownList ID="yGrouping" runat="server" AutoPostBack="true">
<asp:ListItem>Days</asp:ListItem>
<asp:ListItem>Weeks</asp:ListItem>
<asp:ListItem Selected="True">Months</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<dnc:Chart ID="Chart" runat="server" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
- Sample FilenameSurfaceDateGrouping.aspx
- Version6.2
- Uses DatabaseYes