Gallery
Color Swatches Vertical
<%@ 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 generating vertical swatch markup and using them in annotations.
Chart.Size = "600x300";
Chart.Title = ".netCHARTING Vertical Swatches";
Chart.TempDirectory = "temp";
Chart.Debug = true;
Chart.MarginRight = 180;
Chart.LegendBox.Visible = false;
Chart.DefaultElement.ShowValue = true;
// *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();
// Add the random data.
Chart.SeriesCollection.Add(mySC);
// Setup Smart Palette
SmartColor sc2 = new SmartColor(Color.Yellow, Color.Red, new ScaleRange(0, 50));
Chart.SmartPalette.Add("*", sc2);
Annotation an2 = new Annotation(getSwatchA( Chart.SmartPalette, 10, true));
an2.Position = new Point(430, 20);
an2.Header.Label.Text = "Swatch A";
Chart.Annotations.Add(an2);
Annotation an3 = new Annotation(getSwatchB(Chart.SmartPalette, 10));
an3.Position = new Point(470, 70);
an3.Header.Label.Text = "Swatch B";
Chart.Annotations.Add(an3);
Annotation an6 = new Annotation(getSwatchC(Chart.SmartPalette, 10));
an6.Position = new Point(520, 120);
an6.Header.Label.Text = "Swatch C";
Chart.Annotations.Add(an6);
foreach (Annotation anno in Chart.Annotations)
{
anno.ClearColors();
anno.Size = new Size(0, 150);
anno.Label.Alignment = StringAlignment.Center;
anno.Header.StartCap = BoxCapStyle.Torn;
anno.Header.EndCap = BoxCapStyle.Torn;
anno.Header.Offset = new Point(0, -3);
}
}
string getSwatchA( SmartPalette sp, int divisions, bool withValues)
{
// Get Maximum Value of the smart palette range
double max = (double)sp.GetScaleRange("*").ValueHigh;
string swatch = "";
// Generate swatch string for each division.
for (int i = 0; i <= divisions; i++)
{
// Get the color of the current division.
string color = getHTMLColor(sp.GetValueColor("", (i * (max / divisions))));
if (withValues)
swatch += "<block bgColor='" + color + "'>" + (int)(i * (max / divisions)) + "<row>";
else
swatch += "<block bgColor='" + color + "' fColor='Transparent'>__<row>";
}
//return the swatch string.
return swatch;
}
string getSwatchB(SmartPalette sp, int divisions)
{
// Get Maximum Value of the smart palette range
double max = (double)sp.GetScaleRange("*").ValueHigh;
string swatch = "";
// Generate swatch string for each division.
for (int i = 0; i <= divisions; i++)
{
// Get the color of the current division.
string color = getHTMLColor(sp.GetValueColor("", (i * (max / divisions))));
if (i == 0 || i == divisions || i == (int)(divisions / 2))
swatch += "<block bgColor='" + color + "' fColor='Transparent'>__<block>" + (int)(i * (max / divisions)) + "<row>";
else
swatch += "<block bgColor='" + color + "' fColor='Transparent'>__<block><row>";
}
//return the swatch string.
return swatch;
}
string getSwatchC(SmartPalette sp, int divisions)
{
// Get Maximum Value of the smart palette range
double max = (double)sp.GetScaleRange("*").ValueHigh;
string swatch = "";
// Generate swatch string for each division.
for (int i = 0; i <= divisions; i++)
{
// Get the color of the current division.
string color = getHTMLColor(sp.GetValueColor("", (i * (max / divisions))));
if (i == 0)
swatch += "<Chart:Image src='../../images/error0.png'><block bgColor='" + color + "' fColor='Transparent'>__<block>" + (int)(i * (max / divisions)) + "<row>";
else if (i == (int)(divisions / 2))
swatch += "<Chart:Image src='../../images/error.png'><block bgColor='" + color + "' fColor='Transparent'>__<block>" + (int)(i * (max / divisions)) + "<row>";
else if (i == divisions)
swatch += "<Chart:Image src='../../images/error2.png'><block bgColor='" + color + "' fColor='Transparent'>__<block>" + (int)(i * (max / divisions)) + "<row>";
else
swatch += "<block><block bgColor='" + color + "' fColor='Transparent'>__<block><row>";
}
//return the swatch string.
return swatch;
}
string getHTMLColor(Color c)
{
return "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
}
SeriesCollection getRandomData()
{
Random myR = new Random(4);
SeriesCollection SC = new SeriesCollection();
for (int a = 1; a < 2; a++)
{
Series s = new Series("Series " + a.ToString());
int count = 5 + myR.Next(20);
for (int b = 1; b < 15; 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>
<asp:Label ID="Label1" runat="server" />
</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 generating vertical swatch markup and using them in annotations.
Chart.Size = "600x300"
Chart.Title = ".netCHARTING Vertical Swatches"
Chart.TempDirectory = "temp"
Chart.Debug = True
Chart.MarginRight = 180
Chart.LegendBox.Visible = False
Chart.DefaultElement.ShowValue = True
' *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()
' Add the random data.
Chart.SeriesCollection.Add(mySC)
' Setup Smart Palette
Dim sc2 As SmartColor = New SmartColor(Color.Yellow, Color.Red, New ScaleRange(0, 50))
Chart.SmartPalette.Add("*", sc2)
Dim an2 As Annotation = New Annotation(getSwatchA(Chart.SmartPalette, 10, True))
an2.Position = New Point(430, 20)
an2.Header.Label.Text = "Swatch A"
Chart.Annotations.Add(an2)
Dim an3 As Annotation = New Annotation(getSwatchB(Chart.SmartPalette, 10))
an3.Position = New Point(470, 70)
an3.Header.Label.Text = "Swatch B"
Chart.Annotations.Add(an3)
Dim an6 As Annotation = New Annotation(getSwatchC(Chart.SmartPalette, 10))
an6.Position = New Point(520, 120)
an6.Header.Label.Text = "Swatch C"
Chart.Annotations.Add(an6)
For Each anno As Annotation In Chart.Annotations
anno.ClearColors()
anno.Size = New Size(0, 150)
anno.Label.Alignment = StringAlignment.Center
anno.Header.StartCap = BoxCapStyle.Torn
anno.Header.EndCap = BoxCapStyle.Torn
anno.Header.Offset = New Point(0, -3)
Next anno
End Sub
Function getSwatchA(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 = ""
' Generate swatch string for each division.
For i As Integer = 0 To divisions
' Get the color of the current division.
Dim color As String = getHTMLColor(sp.GetValueColor("", (i * (max / divisions))))
If withValues Then
swatch &= "<block bgColor='" & color & "'>" & CInt(Fix(i * (max / divisions))) & "<row>"
Else
swatch &= "<block bgColor='" & color & "' fColor='Transparent'>__<row>"
End If
Next i
'return the swatch string.
Return swatch
End Function
Function getSwatchB(ByVal sp As SmartPalette, ByVal divisions As Integer) As String
' Get Maximum Value of the smart palette range
Dim max As Double = CDbl(sp.GetScaleRange("*").ValueHigh)
Dim swatch As String = ""
' Generate swatch string for each division.
For i As Integer = 0 To divisions
' Get the color of the current division.
Dim color As String = getHTMLColor(sp.GetValueColor("", (i * (max / divisions))))
If i = 0 OrElse i = divisions OrElse i = CInt(Fix(divisions / 2)) Then
swatch &= "<block bgColor='" & color & "' fColor='Transparent'>__<block>" & CInt(Fix(i * (max / divisions))) & "<row>"
Else
swatch &= "<block bgColor='" & color & "' fColor='Transparent'>__<block><row>"
End If
Next i
'return the swatch string.
Return swatch
End Function
Function getSwatchC(ByVal sp As SmartPalette, ByVal divisions As Integer) As String
' Get Maximum Value of the smart palette range
Dim max As Double = CDbl(sp.GetScaleRange("*").ValueHigh)
Dim swatch As String = ""
' Generate swatch string for each division.
For i As Integer = 0 To divisions
' Get the color of the current division.
Dim color As String = getHTMLColor(sp.GetValueColor("", (i * (max / divisions))))
If i = 0 Then
swatch &= "<Chart:Image src='../../images/error0.png'><block bgColor='" & color & "' fColor='Transparent'>__<block>" & CInt(Fix(i * (max / divisions))) & "<row>"
ElseIf i = CInt(Fix(divisions / 2)) Then
swatch &= "<Chart:Image src='../../images/error.png'><block bgColor='" & color & "' fColor='Transparent'>__<block>" & CInt(Fix(i * (max / divisions))) & "<row>"
ElseIf i = divisions Then
swatch &= "<Chart:Image src='../../images/error2.png'><block bgColor='" & color & "' fColor='Transparent'>__<block>" & CInt(Fix(i * (max / divisions))) & "<row>"
Else
swatch &= "<block><block bgColor='" & color & "' fColor='Transparent'>__<block><row>"
End If
Next i
'return the swatch string.
Return 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(4)
Dim SC As SeriesCollection = New SeriesCollection()
For a As Integer = 1 To 1
Dim s As Series = New Series("Series " & a.ToString())
Dim count As Integer = 5 + myR.Next(20)
For b As Integer = 1 To 14
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>
<asp:Label ID="Label1" runat="server" />
</body>
</html>
- Sample FilenameColorSwatchesVertical.aspx
- Version6.1
- Uses DatabaseNo