Gallery
JS Color Range Bubbles
<%@ 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 using a color range to color bubbles based on their size.
Chart.JS.Enabled = true;
Chart.JS.Buttons.EnableExportButton = false;
Chart.JS.Buttons.EnablePrintButton = false;
//Chart Styling
Chart.Size = "600x350";
Chart.TempDirectory = "temp";
Chart.DefaultSeries.Type = SeriesType.Bubble;
Chart.DefaultElement.Transparency = 10;
Chart.MaximumBubbleSize = 40;
Chart.LegendBox.Visible = false;
Chart.ShadingEffectMode = ShadingEffectMode.Three;
Chart.YAxis.AlternateGridBackground.Color = Color.Empty;
// Titlebox Styling
Chart.TitleBox.CornerTopLeft = BoxCorner.Round;
Chart.TitleBox.CornerTopRight = BoxCorner.Round;
Chart.TitleBox.Position = TitleBoxPosition.Full;
Chart.TitleBox.Background.ShadingEffectMode = ShadingEffectMode.Five;
Chart.TitleBox.Background.Color = Color.LightGray;
SmartColor sc2 = new SmartColor(Color.Yellow, Color.Green, new ScaleRange(0, 50), ElementValue.BubbleSize);
Chart.SmartPalette.Add("*", sc2);
// *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();
// This will help draw the smaller bubbles in front.
mySC[0].Sort(ElementValue.BubbleSize, "Asc");
// Add the random data.
Chart.SeriesCollection.Add(mySC);
swatchLabel.Text += getSwatchHTML(580, Chart.SmartPalette, 10, true);
}
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;margin-left:auto;margin-right:auto;\"><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(1);
SeriesCollection SC = new SeriesCollection();
for (int a = 1; a < 2; a++)
{
Series s = new Series("Series " + a.ToString());
for (int b = 1; b < 250; b++)
{
Element e = new Element();//"Element " + b.ToString());
e.YValue = myR.Next(50);
e.XValue = myR.Next(50);
e.BubbleSize = myR.Next(50);
s.Elements.Add(e);
}
SC.Add(s);
}
return SC;
}
SeriesCollection getLiveData()
{
DataEngine de = new DataEngine("ConnectionString goes here");
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 style="margin-left:auto;margin-right:auto;width:600px;">
<div align="center"> <asp:Label ID="swatchLabel" runat="server" />
<dnc:Chart ID="Chart" runat="server" />
</div>
</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 using a color range to color bubbles based on their size.
Chart.JS.Enabled = True
Chart.JS.Buttons.EnableExportButton = False
Chart.JS.Buttons.EnablePrintButton = False
'Chart Styling
Chart.Size = "600x350"
Chart.TempDirectory = "temp"
Chart.DefaultSeries.Type = SeriesType.Bubble
Chart.DefaultElement.Transparency = 10
Chart.MaximumBubbleSize = 40
Chart.LegendBox.Visible = False
Chart.ShadingEffectMode = ShadingEffectMode.Three
Chart.YAxis.AlternateGridBackground.Color = Color.Empty
' Titlebox Styling
Chart.TitleBox.CornerTopLeft = BoxCorner.Round
Chart.TitleBox.CornerTopRight = BoxCorner.Round
Chart.TitleBox.Position = TitleBoxPosition.Full
Chart.TitleBox.Background.ShadingEffectMode = ShadingEffectMode.Five
Chart.TitleBox.Background.Color = Color.LightGray
Dim sc2 As SmartColor = New SmartColor(Color.Yellow, Color.Green, New ScaleRange(0, 50), ElementValue.BubbleSize)
Chart.SmartPalette.Add("*", sc2)
' *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()
' This will help draw the smaller bubbles in front.
mySC(0).Sort(ElementValue.BubbleSize, "Asc")
' Add the random data.
Chart.SeriesCollection.Add(mySC)
swatchLabel.Text += getSwatchHTML(580, Chart.SmartPalette, 10, True)
End Sub
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;margin-left:auto;margin-right:auto;""><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(1)
Dim SC As SeriesCollection = New SeriesCollection()
For a As Integer = 1 To 1
Dim s As Series = New Series("Series " & a.ToString())
For b As Integer = 1 To 249
Dim e As Element = New Element() '"Element " + b.ToString());
e.YValue = myR.Next(50)
e.XValue = myR.Next(50)
e.BubbleSize = myR.Next(50)
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("ConnectionString goes here")
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 style="margin-left:auto;margin-right:auto;width:600px;">
<div align="center"> <asp:Label ID="swatchLabel" runat="server" />
<dnc:Chart ID="Chart" runat="server" />
</div>
</div>
</body>
</html>
- Sample FilenameJsColorRangeBubbles.aspx
- Version10.0
- Uses DatabaseNo