```<%@ Page Language="C#" EnableViewState="false" %>
<%@OutputCache Duration="86400" VaryByParam="*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>Simple Excel Compatible Range Image using ASP.NET and C#</title>
<meta content="Simple Excel Compatible Range Image with ASP.NET, C# and SpreadsheetGear, a royalty free Microsoft Excel compatible spreadsheet component for the Microsoft .NET Framework featuring the fastest and most complete calculation engine available. Create, read, modify, calculate and write Microsoft Excel workbooks from your Microsoft .NET, ASP.NET, C#, VB.NET and Microsoft Office solutions. Integrates with Microsoft Visual Studio .NET, including IntelliSense and Dynamic Help." name="description" />
<script language="C#" runat="server">

{
// Create a new workbook.

dataCells.Value = new string[,] {
{ "\$3,723", "\$5,954", "\$3,522", "\$7,701" },
{ "\$2,681", "\$8,665", "\$5,836", "\$7,851" },
{ "\$3,739", "\$2,107", "\$3,298", "\$8,711" },
{ "\$1,459", "\$7,385", "\$2,125", "\$9,070" }, };

// Create row headings for four quarters
quarterCells.Value = new string[,] { { "Q1" }, { "Q2" }, { "Q3" }, { "Q4" } };

// Create column headings for four regions.
regionCells.Value = new string[,] { { "North", "South", "East", "West" } };

// Add formulas which use the SUM worksheet function to total sales by region.
totalCells.Formula = "=SUM(B2:B5)";
totalCells.NumberFormat = "\$#,##0_);(\$#,##0)";

// Add a chart to the worksheet's shape collection.
// NOTE: Calculate the coordinates of the chart by converting row and column
//       coordinates to points.  Use fractional row and colum values to get
//       coordinates anywhere in between row and column boundaries.
double left = 5;
double top = windowInfo.RowToPoints(6.0) + 5;
double right = windowInfo.ColumnToPoints(5.0) - 5;
double bottom = windowInfo.RowToPoints(16.0) - 5;
worksheet.Shapes.AddChart(left, top, right - left, bottom - top).Chart;

// Set the chart's source data range, plotting series in rows.

// Set the chart type to a pie chart.

// Increase the first pie slice angle.
chart.ChartGroups[0].FirstSliceAngle = 30;

// Get a reference to the first and only series.

// Link category labels to the region cells.
series.XValues = regionCells;

// Add series data labels and change to show percentage only.
series.HasDataLabels = true;
series.DataLabels.ShowPercentage = true;
series.DataLabels.ShowValue = false;

// Explode the first pie slice (North Region).
series.Points[0].Explosion = 25;

// Add a chart title and change the font size.
chart.HasTitle = true;
chart.ChartTitle.Text = "Percentage of Sales by Region";
chart.ChartTitle.Font.Size = 12;

// Create the image class from a specified range.

// Get a new bitmap image of the represented range.
using (System.Drawing.Bitmap bitmap = image.GetBitmap())
{
// Stream the image to the client in PNG format.
Response.Clear();
Response.ContentType = "image/png";
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
memoryStream.WriteTo(Response.OutputStream);
}
}

</script>