Gallery
Chart Micro Pie
<%@ 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 MicroCharts as pie labels to give more detail about the data.
Chart.Type = ChartType.Pies;
Chart.Size = "600x350";
Chart.Title = "January 2009 Sales";
Chart.TempDirectory = "temp";
Chart.Debug = true;
Chart.Use3D = true;
Chart.DefaultElement.ShowValue = true;
Chart.YAxis.FormatString = "Currency";
Chart.LegendBox.Visible = false;
// Get the same data as for the first chart.
SeriesCollection mySC = getRandomData();
// Transpose it to get a sum series (3 bars).
mySC.Transpose();
Series sum = mySC.Calculate("", Calculation.Sum);
// Color each bar separately.
sum.Palette = ChartPalettes.GetPalette(Palette.Default);
Chart.SeriesCollection.Add(sum);
// Transpose it back.
mySC.Transpose();
// Set the label for each bar manualy getting the daily values from the original mySC collection.
int i = 0;
foreach (Series s in mySC)
{
sum[i++].SmartLabel.Text = "<Chart:Column color='DarkGray' values='" + s.GetYValueList() + "' width='100'><row><block fStyle='Bold' hAlign='Center'>%Name - %YValue";
}
}
SeriesCollection getRandomData()
{
Random myR = new Random(2);
SeriesCollection SC = new SeriesCollection();
for (int a = 1; a < 5; a++)
{
Series s = new Series("Product " + a.ToString());
for (int b = 1; b < 30; b++)
{
Element e = new Element();
e.YValue = myR.Next(50);
if (a == 1) e.YValue = myR.Next(20);
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 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" %>
<%@ 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 MicroCharts as pie labels to give more detail about the data.
Chart.Type = ChartType.Pies
Chart.Size = "600x350"
Chart.Title = "January 2009 Sales"
Chart.TempDirectory = "temp"
Chart.Debug = True
Chart.Use3D = True
Chart.DefaultElement.ShowValue = True
Chart.YAxis.FormatString = "Currency"
Chart.LegendBox.Visible = False
' Get the same data as for the first chart.
Dim mySC As SeriesCollection = getRandomData()
' Transpose it to get a sum series (3 bars).
mySC.Transpose()
Dim sum As Series = mySC.Calculate("", Calculation.Sum)
' Color each bar separately.
sum.Palette = ChartPalettes.GetPalette(Palette.Default)
Chart.SeriesCollection.Add(sum)
' Transpose it back.
mySC.Transpose()
' Set the label for each bar manualy getting the daily values from the original mySC collection.
Dim i As Integer = 0
For Each s As Series In mySC
sum(i).SmartLabel.Text = "<Chart:Column color='DarkGray' values='" & s.GetYValueList() & "' width='100'><row><block fStyle='Bold' hAlign='Center'>%Name - %YValue"
i += 1
Next s
End Sub
Function getRandomData() As SeriesCollection
Dim myR As Random = New Random(2)
Dim SC As SeriesCollection = New SeriesCollection()
For a As Integer = 1 To 4
Dim s As Series = New Series("Product " & a.ToString())
For b As Integer = 1 To 29
Dim e As Element = New Element()
e.YValue = myR.Next(50)
If a = 1 Then
e.YValue = myR.Next(20)
End If
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 align="center">
<dnc:Chart ID="Chart" runat="server" />
</div>
</body>
</html>
- Sample FilenameChartMicroPie.aspx
- Version5.2
- Uses DatabaseNo