com.aspose.words
Class ChartSeries

java.lang.Object
    extended by com.aspose.words.ChartSeries
All Implemented Interfaces:
IChartDataPoint, java.lang.Cloneable

public class ChartSeries 
extends java.lang.Object

Represents chart series properties.

Example:

Shows how to apply labels to data points in a chart.
public void chartDataLabels() throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Use a document builder to insert a bar chart
    Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);

    // Get the chart object from the containing shape
    Chart chart = chartShape.getChart();

    // The chart already contains demo data comprised of 3 series each with 4 categories
    Assert.assertEquals(chart.getSeries().getCount(), 3);
    Assert.assertEquals(chart.getSeries().get(0).getName(), "Series 1");

    // Apply data labels to every series in the graph
    for (ChartSeries series : chart.getSeries()) {
        applyDataLabels(series, 4, "000.0", ", ");
        Assert.assertEquals(series.getDataLabels().getCount(), 4);
    }

    // Get the enumerator for a data label collection
    Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();

    // And use it to go over all the data labels in one series and change their separator
    while (enumerator.hasNext()) {
        Assert.assertEquals(enumerator.next().getSeparator(), ", ");
        enumerator.next().setSeparator(" & ");
    }

    // If the chart looks too busy, we can remove data labels one by one
    chart.getSeries().get(1).getDataLabels().removeAt(2);

    // We can also clear an entire data label collection for one whole series
    chart.getSeries().get(2).getDataLabels().clear();

    doc.save(getArtifactsDir() + "Charts.ChartDataLabels.docx");
}

/// <summary>
/// Apply uniform data labels with custom number format and separator to a number (determined by labelsCount) of data points in a series
/// </summary>
private void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        ChartDataLabel label = series.getDataLabels().add(i);
        Assert.assertFalse(label.isVisible());

        // Edit the appearance of the new data label
        label.setShowCategoryName(true);
        label.setShowSeriesName(true);
        label.setShowValue(true);
        label.setShowLeaderLines(true);
        label.setShowLegendKey(true);
        label.setShowPercentage(false);
        Assert.assertFalse(label.getShowDataLabelsRange());

        // Apply number format and separator
        label.getNumberFormat().setFormatCode(numberFormat);
        label.setSeparator(separator);

        // The label automatically becomes visible
        Assert.assertTrue(label.isVisible());
    }
}

Property Getters/Setters Summary
booleangetBubble3D()
voidsetBubble3D(boolean value)
          
ChartDataLabelCollectiongetDataLabels()
           Specifies the settings for the data labels for the entire series.
ChartDataPointCollectiongetDataPoints()
           Returns a collection of formatting objects for all data points in this series.
intgetExplosion()
voidsetExplosion(int value)
          
booleangetInvertIfNegative()
voidsetInvertIfNegative(boolean value)
          
ChartMarkergetMarker()
          
java.lang.StringgetName()
voidsetName(java.lang.String value)
           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.
booleangetSmooth()
voidsetSmooth(boolean value)
           Allows to specify whether the line connecting the points on the chart shall be smoothed using Catmull-Rom splines.
 

Property Getters/Setters Detail

getBubble3D/setBubble3D

public boolean getBubble3D() / public void setBubble3D(boolean value)

getDataLabels

public ChartDataLabelCollection getDataLabels()
Specifies the settings for the data labels for the entire series.

Example:

Shows how to apply labels to data points in a chart.
public void chartDataLabels() throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Use a document builder to insert a bar chart
    Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);

    // Get the chart object from the containing shape
    Chart chart = chartShape.getChart();

    // The chart already contains demo data comprised of 3 series each with 4 categories
    Assert.assertEquals(chart.getSeries().getCount(), 3);
    Assert.assertEquals(chart.getSeries().get(0).getName(), "Series 1");

    // Apply data labels to every series in the graph
    for (ChartSeries series : chart.getSeries()) {
        applyDataLabels(series, 4, "000.0", ", ");
        Assert.assertEquals(series.getDataLabels().getCount(), 4);
    }

    // Get the enumerator for a data label collection
    Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();

    // And use it to go over all the data labels in one series and change their separator
    while (enumerator.hasNext()) {
        Assert.assertEquals(enumerator.next().getSeparator(), ", ");
        enumerator.next().setSeparator(" & ");
    }

    // If the chart looks too busy, we can remove data labels one by one
    chart.getSeries().get(1).getDataLabels().removeAt(2);

    // We can also clear an entire data label collection for one whole series
    chart.getSeries().get(2).getDataLabels().clear();

    doc.save(getArtifactsDir() + "Charts.ChartDataLabels.docx");
}

/// <summary>
/// Apply uniform data labels with custom number format and separator to a number (determined by labelsCount) of data points in a series
/// </summary>
private void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        ChartDataLabel label = series.getDataLabels().add(i);
        Assert.assertFalse(label.isVisible());

        // Edit the appearance of the new data label
        label.setShowCategoryName(true);
        label.setShowSeriesName(true);
        label.setShowValue(true);
        label.setShowLeaderLines(true);
        label.setShowLegendKey(true);
        label.setShowPercentage(false);
        Assert.assertFalse(label.getShowDataLabelsRange());

        // Apply number format and separator
        label.getNumberFormat().setFormatCode(numberFormat);
        label.setSeparator(separator);

        // The label automatically becomes visible
        Assert.assertTrue(label.isVisible());
    }
}

getDataPoints

public ChartDataPointCollection getDataPoints()
Returns a collection of formatting objects for all data points in this series.

Example:

Shows how to apply labels to data points in a chart.
public void chartDataLabels() throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Use a document builder to insert a bar chart
    Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);

    // Get the chart object from the containing shape
    Chart chart = chartShape.getChart();

    // The chart already contains demo data comprised of 3 series each with 4 categories
    Assert.assertEquals(chart.getSeries().getCount(), 3);
    Assert.assertEquals(chart.getSeries().get(0).getName(), "Series 1");

    // Apply data labels to every series in the graph
    for (ChartSeries series : chart.getSeries()) {
        applyDataLabels(series, 4, "000.0", ", ");
        Assert.assertEquals(series.getDataLabels().getCount(), 4);
    }

    // Get the enumerator for a data label collection
    Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();

    // And use it to go over all the data labels in one series and change their separator
    while (enumerator.hasNext()) {
        Assert.assertEquals(enumerator.next().getSeparator(), ", ");
        enumerator.next().setSeparator(" & ");
    }

    // If the chart looks too busy, we can remove data labels one by one
    chart.getSeries().get(1).getDataLabels().removeAt(2);

    // We can also clear an entire data label collection for one whole series
    chart.getSeries().get(2).getDataLabels().clear();

    doc.save(getArtifactsDir() + "Charts.ChartDataLabels.docx");
}

/// <summary>
/// Apply uniform data labels with custom number format and separator to a number (determined by labelsCount) of data points in a series
/// </summary>
private void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        ChartDataLabel label = series.getDataLabels().add(i);
        Assert.assertFalse(label.isVisible());

        // Edit the appearance of the new data label
        label.setShowCategoryName(true);
        label.setShowSeriesName(true);
        label.setShowValue(true);
        label.setShowLeaderLines(true);
        label.setShowLegendKey(true);
        label.setShowPercentage(false);
        Assert.assertFalse(label.getShowDataLabelsRange());

        // Apply number format and separator
        label.getNumberFormat().setFormatCode(numberFormat);
        label.setSeparator(separator);

        // The label automatically becomes visible
        Assert.assertTrue(label.isVisible());
    }
}

getExplosion/setExplosion

public int getExplosion() / public void setExplosion(int value)

getInvertIfNegative/setInvertIfNegative

public boolean getInvertIfNegative() / public void setInvertIfNegative(boolean value)

getMarker

public ChartMarker getMarker()

getName/setName

public java.lang.String getName() / public void setName(java.lang.String value)
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.

Example:

Shows how to apply labels to data points in a chart.
public void chartDataLabels() throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Use a document builder to insert a bar chart
    Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);

    // Get the chart object from the containing shape
    Chart chart = chartShape.getChart();

    // The chart already contains demo data comprised of 3 series each with 4 categories
    Assert.assertEquals(chart.getSeries().getCount(), 3);
    Assert.assertEquals(chart.getSeries().get(0).getName(), "Series 1");

    // Apply data labels to every series in the graph
    for (ChartSeries series : chart.getSeries()) {
        applyDataLabels(series, 4, "000.0", ", ");
        Assert.assertEquals(series.getDataLabels().getCount(), 4);
    }

    // Get the enumerator for a data label collection
    Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();

    // And use it to go over all the data labels in one series and change their separator
    while (enumerator.hasNext()) {
        Assert.assertEquals(enumerator.next().getSeparator(), ", ");
        enumerator.next().setSeparator(" & ");
    }

    // If the chart looks too busy, we can remove data labels one by one
    chart.getSeries().get(1).getDataLabels().removeAt(2);

    // We can also clear an entire data label collection for one whole series
    chart.getSeries().get(2).getDataLabels().clear();

    doc.save(getArtifactsDir() + "Charts.ChartDataLabels.docx");
}

/// <summary>
/// Apply uniform data labels with custom number format and separator to a number (determined by labelsCount) of data points in a series
/// </summary>
private void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        ChartDataLabel label = series.getDataLabels().add(i);
        Assert.assertFalse(label.isVisible());

        // Edit the appearance of the new data label
        label.setShowCategoryName(true);
        label.setShowSeriesName(true);
        label.setShowValue(true);
        label.setShowLeaderLines(true);
        label.setShowLegendKey(true);
        label.setShowPercentage(false);
        Assert.assertFalse(label.getShowDataLabelsRange());

        // Apply number format and separator
        label.getNumberFormat().setFormatCode(numberFormat);
        label.setSeparator(separator);

        // The label automatically becomes visible
        Assert.assertTrue(label.isVisible());
    }
}

getSmooth/setSmooth

public boolean getSmooth() / public void setSmooth(boolean value)
Allows to specify whether the line connecting the points on the chart shall be smoothed using Catmull-Rom splines.

Example:

Shows how to customize chart data points.
@Test
public void chartDataPoint() throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Add a line chart, which will have default data that we will use
    Shape shape = builder.insertChart(ChartType.LINE, 500.0, 350.0);
    Chart chart = shape.getChart();

    // Apply diamond-shaped data points to the line of the first series
    for (ChartSeries series : chart.getSeries()) {
        applyDataPoints(series, 4, MarkerSymbol.DIAMOND, 15);
    }

    // We can further decorate a series line by smoothing it
    chart.getSeries().get(0).setSmooth(true);

    // Get the enumerator for the data point collection from one series
    Iterator<ChartDataPoint> enumerator = chart.getSeries().get(0).getDataPoints().iterator();

    // And use it to go over all the data labels in one series and change their separator
    while (enumerator.hasNext()) {
        Assert.assertFalse(enumerator.next().getInvertIfNegative());
    }

    // If the chart looks too busy, we can remove data points one by one
    chart.getSeries().get(1).getDataPoints().removeAt(2);

    // We can also clear an entire data point collection for one whole series
    chart.getSeries().get(2).getDataPoints().clear();

    doc.save(getArtifactsDir() + "Charts.ChartDataPoint.docx");
}

/// <summary>
/// Applies a number of data points to a series
/// </summary>
private void applyDataPoints(ChartSeries series, int dataPointsCount, /*MarkerSymbol*/int markerSymbol, int dataPointSize) {
    for (int i = 0; i < dataPointsCount; i++) {
        ChartDataPoint point = series.getDataPoints().add(i);
        point.getMarker().setSymbol(markerSymbol);
        point.getMarker().setSize(dataPointSize);

        Assert.assertEquals(point.getIndex(), i);
    }
}

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.