Powered by SpreadsheetGear
<%@ Page Language="C#" EnableViewState="false" %>
<!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>Basic Chart using ASP.NET and C# - Returns Open XML (XLSX) Workbook Using SpreadsheetGear</title>
<meta content="Basic Chart 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">

    void Page_Load(Object sender, EventArgs e)
        // Create a new workbook.
        SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();
        SpreadsheetGear.IWorksheet worksheet = workbook.Worksheets["Sheet1"];
        SpreadsheetGear.IWorksheetWindowInfo windowInfo = worksheet.WindowInfo;

        // Load some sample data.
        SpreadsheetGear.IRange dataRange = worksheet.Cells["A2:A13"];
        dataRange.Formula = "=INT(RAND() * 10 + 5)";

        // 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 = windowInfo.ColumnToPoints(2.0);
        double top = windowInfo.RowToPoints(1.0);
        double right = windowInfo.ColumnToPoints(9.0);
        double bottom = windowInfo.RowToPoints(16.0);
        SpreadsheetGear.Charts.IChart chart =
            worksheet.Shapes.AddChart(left, top, right - left, bottom - top).Chart;

        // Set the chart's source data range, plotting series in columns.
        chart.SetSourceData(dataRange, SpreadsheetGear.Charts.RowCol.Columns);

        // Set the chart type.
        chart.ChartType = SpreadsheetGear.Charts.ChartType.Area;

        // Stream the Excel workbook to the client in the Open XML file
        // format compatible with Excel 2007-2019 and Excel for Office 365.
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
        Response.AddHeader("Content-Disposition", "attachment; filename=report.xlsx");
        workbook.SaveToStream(Response.OutputStream, SpreadsheetGear.FileFormat.OpenXMLWorkbook);