In previous tutorial, I
used SeriesFactory helper class to assign
values to the chart. This time I will use
the Series property to assign values to the
pie chart. You can use series property or
SeriesFactory class, the result is the same.
using System;
using Super2d3dGraphLibrary;
using System.Collections;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
namespace
TheCodeProject_3dPie
{
public partial class PieChart : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Chart control:
Super2D3dGraph oGraph = new Super2D3dGraph();
// Data variable:
ArrayList[]
numbers = new ArrayList[1];
// Explode flags (one per sector; if flag[i]<>
"", sector[i] will be exploded)
String[]
explode = new String[6];
// Add random data...
Random rnd = new Random();
numbers[0] = new ArrayList();
for (int i = 0; i < 6; i++)
{
numbers[0].Add(rnd.Next(500));
if (i ==
2) // Only explode one sector (example)
{
explode[i] = "1";
}
}
// Legend texts...
string[]
legend = { "January", "February", "March", "April", "June", "July" };
// Customize chart:
oGraph.LicenseeIdentifier = "STAND";
oGraph.Title = "3D Pie Chart";
oGraph.Style = STYLE2D3D.STYLE3D_PIE
;
oGraph.Series = numbers;
oGraph.ValuesLocationStyle =
STYLECAPTIONLOCATION.STYLECAPTIONLOCATION_INSIDE;
oGraph.ValuesFormat = "0"; // No decimals
oGraph.ItemsHighlight = explode;
oGraph.ItemsLegend = legend;
oGraph.ShowItemsLegend = true;
oGraph.ShowLegend = false;
oGraph.ShowDataTable = true;
oGraph.ShowLegendInDataTable = false;
oGraph.BackColor = Color.LightYellow;
oGraph.BackStyle = STYLEBACKGROUND.STYLEBACKGROUND_GRADIENT_TUBULAR_INVERTED;
oGraph.Width = 500;
oGraph.Height = 500;
oGraph.RefreshChart();
// Save image in a temporary buffer (PNG
format for best quality)
MemoryStream io = new MemoryStream();
oGraph.Image.Save(io, ImageFormat.Png);
// Output the content of the buffer to the
browser
Response.Clear();
Response.ContentType = "image/png";
Response.BinaryWrite(io.GetBuffer());
}
}
}