Gallery
<%@ 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 HTML range color swatches.
//set global properties
Chart.Size = "600x350";
Chart.TempDirectory = "temp";
Chart.Debug = true;
Chart.Mentor = false;
Chart.LegendBox.Visible = false;
//Add some random data.
Chart.SeriesCollection.Add(getRandomData());
SmartColor sc2 = new SmartColor(Color.Yellow, Color.Red, new ScaleRange(0, 50));
sc2.LegendEntry.Visible = false;
Chart.SmartPalette.Add("*", sc2);
swatchLabel.Text = "Automatically generated HTML swatches<br><br>";
swatchLabel.Text += "HTML Swatch<br>";
swatchLabel.Text += getSwatchHTML(300, Chart.SmartPalette, 10, false);
swatchLabel.Text += "<br>HTML Swatch with values<br>";
swatchLabel.Text += getSwatchHTML(300, Chart.SmartPalette, 10, true);
swatchLabelV.Text += "<br>Vertical <br>HTML Swatch <br>";
swatchLabelV.Text += getVerticalSwatchHTML(new Size(20, 300), Chart.SmartPalette, 10, true);
}
string getVerticalSwatchHTML(Size size, SmartPalette sp, int divisions, bool withValues)
{
StringBuilder sb = new StringBuilder();
// Get Maximum Value of the smart palette range
double max = (double)sp.GetScaleRange("*").ValueHigh;
// Generate swatch string for each division.
sb.Append("<table cellpadding=\"0\" cellspacing=\"0\" style=\"width: " + size.Width + "px; height: " + size.Height + "px;\">");
for (int i = 0; i <= divisions; i++)
{
// Get the color of the current division.
string color = getHTMLColor(sp.GetValueColor("", (i * (max / divisions))));
sb.Append("<tr><td style=\" text-align: center; background-color: " + color + "\">");
if (withValues)
sb.Append((int)(i * (max / divisions)));
else
sb.Append(" ");
sb.Append("</td></tr>");
}
//return the swatch string.
sb.Append("</table>");
return sb.ToString();
}
string getSwatchHTML(int width, SmartPalette sp, int divisions, bool withValues)
{
StringBuilder sb = new StringBuilder();
// Get Maximum Value of the smart palette range
double max = (double)sp.GetScaleRange("*").ValueHigh;
int cellWidth = width / divisions;
// Generate swatch string for each division.
sb.Append("<table cellpadding=\"0\" cellspacing=\"0\" style=\"width: " + width + "px\"><tr>");
for (int i = 0; i <= divisions; i++)
{
// Get the color of the current division.
string color = getHTMLColor(sp.GetValueColor("", (i * (max / divisions))));
sb.Append("<td style=\" text-align: center; width: " + cellWidth + "px; background-color: " + color + "\">");
if (withValues)
sb.Append((int)(i * (max / divisions)));
else
sb.Append(" ");
sb.Append("</td>");
}
//return the swatch string.
sb.Append("</tr></table>");
return sb.ToString();
}
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;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Sample</title>
<style type="text/css">
table
{
font-family: Arial, Helvetica, sans-serif;
font-size: x-small;
font-weight: normal;
}
</style>
</head>
<body>
<div align="center">
<table>
<tr>
<td>
<dnc:Chart ID="Chart" runat="server" />
</td>
<td>
<asp:Label ID="swatchLabelV" runat="server" />
</td>
<td>
<asp:Label ID="swatchLabel" runat="server" />
</td>
</tr>
</table>
</div>
</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 HTML range color swatches.
'set global properties
Chart.Size = "600x350"
Chart.TempDirectory = "temp"
Chart.Debug = True
Chart.Mentor = False
Chart.LegendBox.Visible = False
'Add some random data.
Chart.SeriesCollection.Add(getRandomData())
Dim sc2 As SmartColor = New SmartColor(Color.Yellow, Color.Red, New ScaleRange(0, 50))
sc2.LegendEntry.Visible = False
Chart.SmartPalette.Add("*", sc2)
swatchLabel.Text = "Automatically generated HTML swatches<br><br>"
swatchLabel.Text &= "HTML Swatch<br>"
swatchLabel.Text += getSwatchHTML(300, Chart.SmartPalette, 10, False)
swatchLabel.Text &= "<br>HTML Swatch with values<br>"
swatchLabel.Text += getSwatchHTML(300, Chart.SmartPalette, 10, True)
swatchLabelV.Text &= "<br>Vertical <br>HTML Swatch <br>"
swatchLabelV.Text += getVerticalSwatchHTML(New Size(20, 300), Chart.SmartPalette, 10, True)
End Sub
Function getVerticalSwatchHTML(ByVal size As Size, ByVal sp As SmartPalette, ByVal divisions As Integer, ByVal withValues As Boolean) As String
Dim sb As StringBuilder = New StringBuilder()
' Get Maximum Value of the smart palette range
Dim max As Double = CDbl(sp.GetScaleRange("*").ValueHigh)
' Generate swatch string for each division.
sb.Append("<table cellpadding=""0"" cellspacing=""0"" style=""width: " & size.Width & "px; height: " & size.Height & "px;"">")
For i As Integer = 0 To divisions
' Get the color of the current division.
Dim color As String = getHTMLColor(sp.GetValueColor("", (i * (max / divisions))))
sb.Append("<tr><td style="" text-align: center; background-color: " & color & """>")
If withValues Then
sb.Append(CInt(Fix(i * (max / divisions))))
Else
sb.Append(" ")
End If
sb.Append("</td></tr>")
Next i
'return the swatch string.
sb.Append("</table>")
Return sb.ToString()
End Function
Function getSwatchHTML(ByVal width As Integer, ByVal sp As SmartPalette, ByVal divisions As Integer, ByVal withValues As Boolean) As String
Dim sb As StringBuilder = New StringBuilder()
' Get Maximum Value of the smart palette range
Dim max As Double = CDbl(sp.GetScaleRange("*").ValueHigh)
Dim cellWidth As Integer = width / divisions
' Generate swatch string for each division.
sb.Append("<table cellpadding=""0"" cellspacing=""0"" style=""width: " & width & "px""><tr>")
For i As Integer = 0 To divisions
' Get the color of the current division.
Dim color As String = getHTMLColor(sp.GetValueColor("", (i * (max / divisions))))
sb.Append("<td style="" text-align: center; width: " & cellWidth & "px; background-color: " & color & """>")
If withValues Then
sb.Append(CInt(Fix(i * (max / divisions))))
Else
sb.Append(" ")
End If
sb.Append("</td>")
Next i
'return the swatch string.
sb.Append("</tr></table>")
Return sb.ToString()
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
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Sample</title>
<style type="text/css">
table
{
font-family: Arial, Helvetica, sans-serif;
font-size: x-small;
font-weight: normal;
}
</style>
</head>
<body>
<div align="center">
<table>
<tr>
<td>
<dnc:Chart ID="Chart" runat="server" />
</td>
<td>
<asp:Label ID="swatchLabelV" runat="server" />
</td>
<td>
<asp:Label ID="swatchLabel" runat="server" />
</td>
</tr>
</table>
</div>
</body>
</html>
- Sample FilenameColorSwatchHTML.aspx
- Version6.1
- Uses DatabaseNo