Table of Contents

Interface IChartSerie

Namespace
Spire.Xls.Core
Assembly
Spire.XLS.dll

Represents a series in the chart.

public interface IChartSerie : IExcelApplication
Inherited Members

Properties

Bubbles

Bubble sizes for the series. The following code illustrates how to set Bubbles for IChartSerie in charts:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set serie
IChartSerie serie = chart.Series.Add(ExcelChartType.Bubble);

//Set values and bubble chart range
serie.Values = worksheet.Range["A1:C1"];;
serie.Bubbles = worksheet.Range["A2:C2"];

//Save to file
workbook.SaveToFile("Chart.xlsx");
IXLSRange Bubbles { get; set; }

Property Value

IXLSRange

CategoryLabels

Category labels for the series. The following code illustrates how to set category labels for IChartSerie in charts:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set serie
IChartSerie serie = chart.Series.Add();

//Set category labels and values
serie.CategoryLabels = worksheet.Range["A1:C1"];
serie.Values = worksheet.Range["A2:C2"];

//Save to file
workbook.SaveToFile("Chart.xlsx");
IXLSRange CategoryLabels { get; set; }

Property Value

IXLSRange

DataLabels

IChartDataLabels DataLabels { get; }

Property Value

IChartDataLabels

DataPoints

Returns collection of data points. Read-only. The following code illustrates how to access the IChartDataPoints collection from IChartSerie:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set range
chart.DataRange = worksheet["A1:C3"];

//Set data points
IChartDataPoints dataPoints = chart.Series[0].DataPoints;

//Set data labels value visibility
dataPoints.DefaultDataPoint.DataLabels.HasValue = true;

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

Property Value

IChartDataPoints

EnteredDirectlyBubbles

Represents bubble values as entered directly. The following code illustrates how series data for second value axis of ExcelChartType.Bubble charts can be directly given for charts:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set serie
IChartSerie serie = chart.Series.Add(ExcelChartType.Bubble);

//Set direct values
serie.EnteredDirectlyValues = new object[] { 10, 20, 30 };

//Set bubble chart direct values
serie.EnteredDirectlyBubbles = new object[] { 1, 4, 2 };

//Save to file
workbook.SaveToFile("Chart.xlsx");
object[] EnteredDirectlyBubbles { get; set; }

Property Value

object[]

EnteredDirectlyCategoryLabels

Represents category values as entered directly. The following code illustrates how series category labels can be directly given for charts:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set serie
IChartSerie serie = chart.Series.Add(ExcelChartType.Pie);

//Set direct values
serie.EnteredDirectlyValues = new object[] { 2000, 1000, 1000 };

//Set direct category label
serie.EnteredDirectlyCategoryLabels = new object[] { "Total Income", "Expenses", "Profit" };

//Save to file
workbook.SaveToFile("Chart.xlsx");
object[] EnteredDirectlyCategoryLabels { get; set; }

Property Value

object[]

EnteredDirectlyValues

Represents value as entered directly. The following code illustrates how series data can be directly given for charts:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set serie
IChartSerie serie = chart.Series.Add(ExcelChartType.Pie);

//Set direct values
serie.EnteredDirectlyValues = new object[] { 2000, 1000, 1000 };

//Set direct category label
serie.EnteredDirectlyCategoryLabels = new object[] { "Total Income", "Expenses", "Profit" };

//Save to file
workbook.SaveToFile("Chart.xlsx");
object[] EnteredDirectlyValues { get; set; }

Property Value

object[]

ErrorBarsX

Represents X error bars. Read only. The following code illustrates how IChartErrorBars in X-axis can be accessed:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set chart type
chart.ChartType = ExcelChartType.ScatterLine;

//Set range
chart.DataRange = worksheet.Range["A1:C2"];

//Set error bar
chart.Series[0].HasErrorBarsX = true;
IChartErrorBars errorBar = chart.Series[0].ErrorBarsX;

//Set error bar type
errorBar.Type = ErrorBarType.Percentage;

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

Property Value

IChartErrorBars

ErrorBarsY

Represents Y error bars. Read only. The following code illustrates how IChartErrorBars on Y-axis can be accessed:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set chart type
chart.ChartType = ExcelChartType.ScatterLine;

//Set range
chart.DataRange = worksheet.Range["A1:C2"];

//Set error bar
chart.Series[0].HasErrorBarsY = true;
IChartErrorBars errorBar = chart.Series[0].ErrorBarsY;

//Set error bar type
errorBar.Type = ErrorBarType.Percentage;

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

Property Value

IChartErrorBars

Format

Returns format of current serie. The following code illustrates how to access the IChartSerieDataFormat from IChartSerie:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set range
chart.DataRange = worksheet["A1:C2"];

//Set chart type
chart.ChartType = ExcelChartType.Line;

//Set serie format
IChartSerieDataFormat format = chart.Series[0].Format;

//Set marker style
format.MarkerStyle = ChartMarkerType.Star;

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

Property Value

IChartSerieDataFormat

HasErrorBarsX

Indicates if serie contains X error bars. The following code illustrates how HasErrorBarsX property can be used:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set chart type
chart.ChartType = ExcelChartType.ScatterLine;

//Set range
chart.DataRange = worksheet.Range["A1:C2"];

//Set error bar
chart.Series[0].HasErrorBarsX = true;

//Save to file
workbook.SaveToFile("Chart.xlsx");
bool HasErrorBarsX { get; set; }

Property Value

bool

HasErrorBarsY

Indicates if serie contains Y error bars. The following code illustrates how HasErrorBarsY property can be used:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set chart type
chart.ChartType = ExcelChartType.ScatterLine;

//Set range
chart.DataRange = worksheet.Range["A1:C2"];

//Set error bar
chart.Series[0].HasErrorBarsY = true;

//Save to file
workbook.SaveToFile("Chart.xlsx");
bool HasErrorBarsY { get; set; }

Property Value

bool

Name

Name of the series. The following code illustrates how to access the name of the IChartSerie:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set serie
IChartSerie serie = chart.Series.Add("BarSerie");

//Set category labels and values
serie.CategoryLabels = worksheet.Range["A1:C1"];
serie.Values = worksheet.Range["A2:C2"];

//Get Serie name
Console.Write(serie.Name);

//Save to file
workbook.SaveToFile("Chart.xlsx");
string Name { get; set; }

Property Value

string

NamedRange

Series Name range for the series.

CellRange NamedRange { get; }

Property Value

CellRange

SerieType

Represents serie type. The following code illustrates how to set SerieType for charts:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set range
chart.DataRange = worksheet["A1:C2"];

//Set chart type
chart.Series[0].SerieType = ExcelChartType.Line;

//Save to file
workbook.SaveToFile("Chart.xlsx");
ExcelChartType SerieType { get; set; }

Property Value

ExcelChartType

TrendLines

Represents serie trend lines collection. Read only. The following code illustrates how IChartTrendLines collection can be accessed from a particular IChartSerie:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set range
chart.DataRange = worksheet.Range["A1:C2"];

//Set trend line
IChartTrendLines trendLines = chart.Series[0].TrendLines;
IChartTrendLine trendLine = trendLines.Add(TrendLineType.Linear);

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

Property Value

IChartTrendLines

UsePrimaryAxis

Indicates whether to use primary axis for series drawing. The following code illustrates how the secondary axis can be used by disabling primary axis:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set range
chart.DataRange = worksheet["A1:C3"];

//Set secondary axis
IChartSerie serie = chart.Series[1];
serie.UsePrimaryAxis = false;
chart.SecondaryCategoryAxis.Visible = true;

//Save to file
workbook.SaveToFile("Chart.xlsx");
bool UsePrimaryAxis { get; set; }

Property Value

bool

Values

Values range for the series. The following code illustrates how to set values for IChartSerie in charts:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set serie
IChartSerie serie = chart.Series.Add();

//Set category labels and values
serie.CategoryLabels = worksheet.Range["A1:C1"];
serie.Values = worksheet.Range["A2:C2"];

//Save to file
workbook.SaveToFile("Chart.xlsx");
IXLSRange Values { get; set; }

Property Value

IXLSRange

Methods

ErrorBar(bool)

Creates error bar object. The following code illustrates how to set IChartErrorBars on Y-axis of a particular IChartSerie:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set range
chart.DataRange = worksheet.Range["A1:C2"];

//Set error bar
chart.Series[0].ErrorBar(true);

//Save to file
workbook.SaveToFile("Chart.xlsx");
IChartErrorBars ErrorBar(bool bIsY)

Parameters

bIsY bool

If true - on Y axis; otherwise on X axis.

Returns

IChartErrorBars

Return error bar objcet.

ErrorBar(bool, IXLSRange, IXLSRange)

Sets custom error bar type. The following code illustrates how an IChartErrorBars can be created on X-axis with IChartErrorBars.PlusRange and IChartErrorBars.MinusRange:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set chart type
chart.ChartType = ExcelChartType.ScatterLine;

//Set range
chart.DataRange = worksheet.Range["A1:C2"];

//Set error bar
chart.Series[0].ErrorBar(false, worksheet.Range["A3"], worksheet.Range["B3"]);

//Save to file
workbook.SaveToFile("Chart.xlsx");
IChartErrorBars ErrorBar(bool bIsY, IXLSRange plusRange, IXLSRange minusRange)

Parameters

bIsY bool

If true - on Y axis; otherwise on X axis.

plusRange IXLSRange

Represents plus range.

minusRange IXLSRange

Represents minus range.

Returns

IChartErrorBars

Returns error bar object.

ErrorBar(bool, ErrorBarIncludeType)

Creates error bar object. The following code illustrates how to set IChartErrorBars with ErrorBarIncludeType.Plus on Y-axis of a particular IChartSerie:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set range
chart.DataRange = worksheet.Range["A1:C2"];

//Set error bar
chart.Series[0].ErrorBar(true, ErrorBarIncludeType.Plus);

//Save to file
workbook.SaveToFile("Chart.xlsx");
IChartErrorBars ErrorBar(bool bIsY, ErrorBarIncludeType include)

Parameters

bIsY bool

If true - on Y axis; otherwise on X axis.

include ErrorBarIncludeType

Represents include type.

Returns

IChartErrorBars

Return error bar objcet.

ErrorBar(bool, ErrorBarIncludeType, ErrorBarType)

Creates error bar object. The following code illustrates how to set IChartErrorBars with ErrorBarIncludeType.Plus and ErrorBarType.Percentage on Y-axis of a particular IChartSerie:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set range
chart.DataRange = worksheet.Range["A1:C2"];

//Set error bar
chart.Series[0].ErrorBar(true, ErrorBarIncludeType.Plus, ErrorBarType.Percentage);

//Save to file
workbook.SaveToFile("Chart.xlsx");
IChartErrorBars ErrorBar(bool bIsY, ErrorBarIncludeType include, ErrorBarType type)

Parameters

bIsY bool

If true - on Y axis; otherwise on X axis.

include ErrorBarIncludeType

Represents include type.

type ErrorBarType

Represents error bar type.

Returns

IChartErrorBars

Return error bar objcet.

ErrorBar(bool, ErrorBarIncludeType, ErrorBarType, double)

Creates error bar object. The following code illustrates how to set IChartErrorBars with ErrorBarIncludeType.Plus , ErrorBarType.Percentage and number value of "50" on Y-axis of a particular IChartSerie:

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

//Create chart
IChart chart = worksheet.Charts.Add();

//Set range
chart.DataRange = worksheet.Range["A1:C2"];

//Set error bar
chart.Series[0].ErrorBar(true, ErrorBarIncludeType.Plus, ErrorBarType.Percentage, 50);

//Save to file
workbook.SaveToFile("Chart.xlsx");
IChartErrorBars ErrorBar(bool bIsY, ErrorBarIncludeType include, ErrorBarType type, double numberValue)

Parameters

bIsY bool

If true - on Y axis; otherwise on X axis.

include ErrorBarIncludeType

Represents include type.

type ErrorBarType

Represents error bar type.

numberValue double

Represents number value.

Returns

IChartErrorBars

Return error bar objcet.