ChartSeries

ChartSeries class

Represents chart series properties.

To learn more, visit the Working with Charts documentation article.

public class ChartSeries : IChartDataPoint

Properties

NameDescription
Bubble3D { get; set; }Specifies whether the bubbles in Bubble chart should have a 3-D effect applied to them.
BubbleSizes { get; }Gets a collection of bubble sizes for this chart series.
DataLabels { get; }Specifies the settings for the data labels for the entire series.
DataPoints { get; }Returns a collection of formatting objects for all data points in this series.
Explosion { get; set; }Specifies the amount the data point shall be moved from the center of the pie. Can be negative, negative means that property is not set and no explosion should be applied. Applies only to Pie charts.
Format { get; }Provides access to fill and line formatting of the series.
HasDataLabels { get; set; }Gets or sets a flag indicating whether data labels are displayed for the series.
InvertIfNegative { get; set; }Specifies whether the parent element shall inverts its colors if the value is negative.
LegendEntry { get; }Gets a legend entry for this chart series.
Marker { get; }Specifies a data marker. Marker is automatically created when requested.
Name { get; set; }Gets or sets the name of the series, if name is not set explicitly it is generated using index. By default returns Series plus one based index.
SeriesType { get; }Gets the type of this chart series.
Smooth { get; set; }Allows to specify whether the line connecting the points on the chart shall be smoothed using Catmull-Rom splines.
XValues { get; }Gets a collection of X values for this chart series.
YValues { get; }Gets a collection of Y values for this chart series.

Methods

NameDescription
Add(ChartXValue)Adds the specified X value to the chart series. If the series supports Y values and bubble sizes, they will be empty for the X value.
Add(ChartXValueChartYValue)Adds the specified X and Y values to the chart series.
Add(ChartXValueChartYValue, double)Adds the specified X value, Y value and bubble size to the chart series.
Clear()Removes all data values from the chart series. Format of all individual data points and data labels is cleared.
ClearValues()Removes all data values from the chart series with preserving the format of the data points and data labels.
CopyFormatFrom(int)Copies default data point format from the data point with the specified index.
Insert(int, ChartXValue)Inserts the specified X value into the chart series at the specified index. If the series supports Y values and bubble sizes, they will be empty for the X value.
Insert(int, ChartXValueChartYValue)Inserts the specified X and Y values into the chart series at the specified index.
Insert(int, ChartXValueChartYValue, double)Inserts the specified X value, Y value and bubble size into the chart series at the specified index.
Remove(int)Removes the X value, Y value, and bubble size, if supported, from the chart series at the specified index. The corresponding data point and data label are also removed.

Examples

Shows how to apply labels to data points in a line chart.

public void DataLabels()
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    Shape chartShape = builder.InsertChart(ChartType.Line, 400, 300);
    Chart chart = chartShape.Chart;

    Assert.AreEqual(3, chart.Series.Count);
    Assert.AreEqual("Series 1", chart.Series[0].Name);
    Assert.AreEqual("Series 2", chart.Series[1].Name);
    Assert.AreEqual("Series 3", chart.Series[2].Name);

    // Apply data labels to every series in the chart.
    // These labels will appear next to each data point in the graph and display its value.
    foreach (ChartSeries series in chart.Series)
    {
        ApplyDataLabels(series, 4, "000.0", ", ");
        Assert.AreEqual(4, series.DataLabels.Count);
    }

    // Change the separator string for every data label in a series.
    using (IEnumerator<ChartDataLabel> enumerator = chart.Series[0].DataLabels.GetEnumerator())
    {
        while (enumerator.MoveNext())
        {
            Assert.AreEqual(", ", enumerator.Current.Separator);
            enumerator.Current.Separator = " & ";
        }
    }

    // For a cleaner looking graph, we can remove data labels individually.
    chart.Series[1].DataLabels[2].ClearFormat();

    // We can also strip an entire series of its data labels at once.
    chart.Series[2].DataLabels.ClearFormat();

    doc.Save(ArtifactsDir + "Charts.DataLabels.docx");
}

/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void ApplyDataLabels(ChartSeries series, int labelsCount, string numberFormat, string separator)
{
    for (int i = 0; i < labelsCount; i++)
    {
        series.HasDataLabels = true;

        Assert.False(series.DataLabels[i].IsVisible);

        series.DataLabels[i].ShowCategoryName = true;
        series.DataLabels[i].ShowSeriesName = true;
        series.DataLabels[i].ShowValue = true;
        series.DataLabels[i].ShowLeaderLines = true;
        series.DataLabels[i].ShowLegendKey = true;
        series.DataLabels[i].ShowPercentage = false;
        series.DataLabels[i].IsHidden = false;
        Assert.False(series.DataLabels[i].ShowDataLabelsRange);

        series.DataLabels[i].NumberFormat.FormatCode = numberFormat;
        series.DataLabels[i].Separator = separator;

        Assert.False(series.DataLabels[i].ShowDataLabelsRange);
        Assert.True(series.DataLabels[i].IsVisible);
        Assert.False(series.DataLabels[i].IsHidden);
    }
}

See Also