Table of Contents

Class Chart

Namespace
Spire.Xls
Assembly
Spire.XLS.dll
public class Chart : XlsChartShape, IDisposable, ICloneParent, INamedObject, IChartShape, IShape, IExcelApplication, IChart
Inheritance
Chart
Implements
Inherited Members

Properties

ChartArea

Returns a ChartArea object that represents the complete chart area for the chart. The following code illustrates how to access IChartFrameFormat using ChartArea property and set foreground color for the ChartArea:

//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//Add data
worksheet.Range["A1"].Text = "Jan";
      worksheet.Range["B1"].Text = "Feb";
      worksheet.Range["C1"].Text = "Mar";
      worksheet.Range["A2"].Text = "10";
      worksheet.Range["B2"].Text = "20";
      worksheet.Range["C2"].Text = "30";

//Create chart and range
Chart chart = worksheet.Charts.Add();
chart.DataRange = worksheet.Range["A1:C2"];

//Set chart frame format
IChartFrameFormat frameFormat = chart.ChartArea;
//Set color
frameFormat.Fill.ForeColor = System.Drawing.Color.Red;

//Save to file
workbook.SaveToFile("Chart.xlsx");
public ChartArea ChartArea { get; }

Property Value

ChartArea

ChartTitleArea

Gets title text area. Read-only.

public ChartTextArea ChartTitleArea { get; }

Property Value

ChartTextArea

DataRange

DataRange for the chart series.

public CellRange DataRange { get; set; }

Property Value

CellRange

DataTable

Returns a DataTable object that represents the chart data table. The following code illustrates how to set HasDataTable to "true" to enable data table and set IChartDataTable.HasBorders to "false" to hide the borders of data table:

//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//Add data
worksheet.Range["A1"].Text = "Jan";
      worksheet.Range["B1"].Text = "Feb";
      worksheet.Range["C1"].Text = "Mar";
      worksheet.Range["A2"].Text = "10";
      worksheet.Range["B2"].Text = "20";
      worksheet.Range["C2"].Text = "30";

//Create chart and range
Chart chart = worksheet.Charts.Add();
chart.DataRange = worksheet.Range["A1:C2"];

//Set Chart data table
chart.HasDataTable = true;
IChartDataTable dataTable = chart.DataTable;
//Set border
dataTable.HasBorders = false;

//Save to file
workbook.SaveToFile("Chart.xlsx");
public ChartDataTable DataTable { get; }

Property Value

ChartDataTable

Floor

Returns a Floor object that represents the floor of the 3-D chart. The following code illustrates how to access IChartWallOrFloor using Floor property and set foreground color for the chart's Floor:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Get chart
Chart chart = worksheet.Charts[0];

//Set chart wall
IChartWallOrFloor floor = chart.Floor;
//Set color
floor.Fill.FillType = ShapeFillType.SolidColor;
floor.Fill.ForeColor = System.Drawing.Color.Red;

//Save to file
workbook.SaveToFile("Chart.xlsx");
public ChartWallOrFloor Floor { get; }

Property Value

ChartWallOrFloor

Legend

Represents chart legend. The following code illustrates how to access IChartLegend using IChart.Legend property and set IChartLegend.Position to LegendPositionType.Left:

//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//Add data
worksheet.Range["A1"].Text = "Jan";
      worksheet.Range["B1"].Text = "Feb";
      worksheet.Range["C1"].Text = "Mar";
      worksheet.Range["A2"].Text = "10";
      worksheet.Range["B2"].Text = "20";
      worksheet.Range["C2"].Text = "30";

//Create chart and range
Chart chart = worksheet.Charts.Add();
chart.DataRange = worksheet.Range["A1:C2"];

//Set chart legend and legend position
IChartLegend legend = chart.Legend;
legend.Position = LegendPositionType.Left;

//Save to file
workbook.SaveToFile("Chart.xlsx");
public ChartLegend Legend { get; }

Property Value

ChartLegend

PageSetup

Page setup for the chart.

public ChartPageSetup PageSetup { get; }

Property Value

ChartPageSetup

PlotArea

Returns a PlotArea object that represents the plot area of a chart. The following code illustrates how to access IChartFrameFormat using PlotArea property and set foreground color for the chart's PlotArea:

//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//Add data
worksheet.Range["A1"].Text = "Jan";
      worksheet.Range["B1"].Text = "Feb";
      worksheet.Range["C1"].Text = "Mar";
      worksheet.Range["A2"].Text = "10";
      worksheet.Range["B2"].Text = "20";
      worksheet.Range["C2"].Text = "30";

//Create chart and range
Chart chart = worksheet.Charts.Add();
chart.DataRange = worksheet.Range["A1:C2"];

//Set chart frame format
IChartFrameFormat frameFormat = chart.PlotArea;
//Set color
frameFormat.Fill.ForeColor = System.Drawing.Color.Red;

//Save to file
workbook.SaveToFile("Chart.xlsx");
public ChartPlotArea PlotArea { get; }

Property Value

ChartPlotArea

PrimaryCategoryAxis

Returns primary category axis.

public ChartCategoryAxis PrimaryCategoryAxis { get; }

Property Value

ChartCategoryAxis

PrimarySerieAxis

Returns primary series axis. Read-only.

public ChartSeriesAxis PrimarySerieAxis { get; }

Property Value

ChartSeriesAxis

PrimaryValueAxis

Returns primary value axis.

public ChartValueAxis PrimaryValueAxis { get; }

Property Value

ChartValueAxis

SecondaryCategoryAxis

Returns secondary category axis.

public ChartCategoryAxis SecondaryCategoryAxis { get; }

Property Value

ChartCategoryAxis

SecondaryValueAxis

Returns secondary value axis. Read-only.

public ChartValueAxis SecondaryValueAxis { get; }

Property Value

ChartValueAxis

Series

Returns an object that represents either a single series (a Series object) or a collection of all the series (a SeriesCollection collection) in the chart or chart group.

public ChartSeries Series { get; }

Property Value

ChartSeries

Walls

Represents chart walls. The following code illustrates how to access IChartWallOrFloor using Walls property and set foreground color for the chart's Walls:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Get chart
Chart chart = worksheet.Charts[0];

//Set chart wall
IChartWallOrFloor wall = chart.Walls;
//Set color
wall.Fill.FillType = ShapeFillType.SolidColor;
wall.Fill.ForeColor = System.Drawing.Color.Red;

//Save to file
workbook.SaveToFile("Chart.xlsx");
public ChartWallOrFloor Walls { get; }

Property Value

ChartWallOrFloor

Workbook

Workbook contains the chart.

public Workbook Workbook { get; }

Property Value

Workbook

Worksheet

Worksheet which contains the chart.

public object Worksheet { get; }

Property Value

object