com.aspose.words

Class ChartSeries

  • java.lang.Object
    • 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 line chart.
public void dataLabels() throws Exception
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
    Chart chart = chartShape.getChart();

    Assert.assertEquals(3, chart.getSeries().getCount());
    Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
    Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
    Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());

    // 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.
    for (ChartSeries series : chart.getSeries())
    {
        applyDataLabels(series, 4, "000.0", ", ");
        Assert.assertEquals(series.getDataLabels().getCount(), 4);
    }

    // Change the separator string for every data label in a series.
    Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
    while (enumerator.hasNext()) {
        Assert.assertEquals(enumerator.next().getSeparator(), ", ");
        enumerator.next().setSeparator(" & ");
    }

    // For a cleaner looking graph, we can remove data labels individually.
    chart.getSeries().get(1).getDataLabels().get(2).clearFormat();

    // We can also strip an entire series of its data labels at once.
    chart.getSeries().get(2).getDataLabels().clearFormat();

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

/// <summary>
/// Apply data labels with custom number format and separator to a number of 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.assertFalse(series.getDataLabels().get(i).isVisible());

        series.getDataLabels().get(i).setShowCategoryName(true);
        series.getDataLabels().get(i).setShowSeriesName(true);
        series.getDataLabels().get(i).setShowValue(true);
        series.getDataLabels().get(i).setShowLeaderLines(true);
        series.getDataLabels().get(i).setShowLegendKey(true);
        series.getDataLabels().get(i).setShowPercentage(false);
        series.getDataLabels().get(i).isHidden(false);
        Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());

        series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
        series.getDataLabels().get(i).setSeparator(separator);

        Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
        Assert.assertTrue(series.getDataLabels().get(i).isVisible());
        Assert.assertFalse(series.getDataLabels().get(i).isHidden());
    }
}

Property Getters/Setters Summary
booleangetBubble3D()
void
setBubble3D(booleanvalue)
          
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()
void
setExplosion(intvalue)
          
booleanhasDataLabels()
void
hasDataLabels(booleanvalue)
           Gets or sets a flag indicating whether data labels are displayed for the series.
booleangetInvertIfNegative()
void
setInvertIfNegative(booleanvalue)
          
ChartMarkergetMarker()
java.lang.StringgetName()
void
setName(java.lang.Stringvalue)
           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()
void
setSmooth(booleanvalue)
           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 line chart.
        public void dataLabels() throws Exception
        {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
        
            Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
            Chart chart = chartShape.getChart();
        
            Assert.assertEquals(3, chart.getSeries().getCount());
            Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
            Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
            Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
        
            // 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.
            for (ChartSeries series : chart.getSeries())
            {
                applyDataLabels(series, 4, "000.0", ", ");
                Assert.assertEquals(series.getDataLabels().getCount(), 4);
            }
        
            // Change the separator string for every data label in a series.
            Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
            while (enumerator.hasNext()) {
                Assert.assertEquals(enumerator.next().getSeparator(), ", ");
                enumerator.next().setSeparator(" & ");
            }
        
            // For a cleaner looking graph, we can remove data labels individually.
            chart.getSeries().get(1).getDataLabels().get(2).clearFormat();
        
            // We can also strip an entire series of its data labels at once.
            chart.getSeries().get(2).getDataLabels().clearFormat();
        
            doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
        }
        
        /// <summary>
        /// Apply data labels with custom number format and separator to a number of 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.assertFalse(series.getDataLabels().get(i).isVisible());
        
                series.getDataLabels().get(i).setShowCategoryName(true);
                series.getDataLabels().get(i).setShowSeriesName(true);
                series.getDataLabels().get(i).setShowValue(true);
                series.getDataLabels().get(i).setShowLeaderLines(true);
                series.getDataLabels().get(i).setShowLegendKey(true);
                series.getDataLabels().get(i).setShowPercentage(false);
                series.getDataLabels().get(i).isHidden(false);
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
        
                series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
                series.getDataLabels().get(i).setSeparator(separator);
        
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
                Assert.assertTrue(series.getDataLabels().get(i).isVisible());
                Assert.assertFalse(series.getDataLabels().get(i).isHidden());
            }
        }
      • 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 line chart.
        public void dataLabels() throws Exception
        {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
        
            Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
            Chart chart = chartShape.getChart();
        
            Assert.assertEquals(3, chart.getSeries().getCount());
            Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
            Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
            Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
        
            // 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.
            for (ChartSeries series : chart.getSeries())
            {
                applyDataLabels(series, 4, "000.0", ", ");
                Assert.assertEquals(series.getDataLabels().getCount(), 4);
            }
        
            // Change the separator string for every data label in a series.
            Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
            while (enumerator.hasNext()) {
                Assert.assertEquals(enumerator.next().getSeparator(), ", ");
                enumerator.next().setSeparator(" & ");
            }
        
            // For a cleaner looking graph, we can remove data labels individually.
            chart.getSeries().get(1).getDataLabels().get(2).clearFormat();
        
            // We can also strip an entire series of its data labels at once.
            chart.getSeries().get(2).getDataLabels().clearFormat();
        
            doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
        }
        
        /// <summary>
        /// Apply data labels with custom number format and separator to a number of 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.assertFalse(series.getDataLabels().get(i).isVisible());
        
                series.getDataLabels().get(i).setShowCategoryName(true);
                series.getDataLabels().get(i).setShowSeriesName(true);
                series.getDataLabels().get(i).setShowValue(true);
                series.getDataLabels().get(i).setShowLeaderLines(true);
                series.getDataLabels().get(i).setShowLegendKey(true);
                series.getDataLabels().get(i).setShowPercentage(false);
                series.getDataLabels().get(i).isHidden(false);
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
        
                series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
                series.getDataLabels().get(i).setSeparator(separator);
        
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
                Assert.assertTrue(series.getDataLabels().get(i).isVisible());
                Assert.assertFalse(series.getDataLabels().get(i).isHidden());
            }
        }
      • getExplosion/setExplosion

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

        public boolean hasDataLabels() / public void hasDataLabels(boolean value)
        
        Gets or sets a flag indicating whether data labels are displayed for the series.
      • getInvertIfNegative/setInvertIfNegative

        public boolean getInvertIfNegative() / public void setInvertIfNegative(boolean value)
        
      • 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 line chart.
        public void dataLabels() throws Exception
        {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
        
            Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
            Chart chart = chartShape.getChart();
        
            Assert.assertEquals(3, chart.getSeries().getCount());
            Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
            Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
            Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
        
            // 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.
            for (ChartSeries series : chart.getSeries())
            {
                applyDataLabels(series, 4, "000.0", ", ");
                Assert.assertEquals(series.getDataLabels().getCount(), 4);
            }
        
            // Change the separator string for every data label in a series.
            Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
            while (enumerator.hasNext()) {
                Assert.assertEquals(enumerator.next().getSeparator(), ", ");
                enumerator.next().setSeparator(" & ");
            }
        
            // For a cleaner looking graph, we can remove data labels individually.
            chart.getSeries().get(1).getDataLabels().get(2).clearFormat();
        
            // We can also strip an entire series of its data labels at once.
            chart.getSeries().get(2).getDataLabels().clearFormat();
        
            doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
        }
        
        /// <summary>
        /// Apply data labels with custom number format and separator to a number of 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.assertFalse(series.getDataLabels().get(i).isVisible());
        
                series.getDataLabels().get(i).setShowCategoryName(true);
                series.getDataLabels().get(i).setShowSeriesName(true);
                series.getDataLabels().get(i).setShowValue(true);
                series.getDataLabels().get(i).setShowLeaderLines(true);
                series.getDataLabels().get(i).setShowLegendKey(true);
                series.getDataLabels().get(i).setShowPercentage(false);
                series.getDataLabels().get(i).isHidden(false);
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
        
                series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
                series.getDataLabels().get(i).setSeparator(separator);
        
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
                Assert.assertTrue(series.getDataLabels().get(i).isVisible());
                Assert.assertFalse(series.getDataLabels().get(i).isHidden());
            }
        }
      • 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 work with data points on a line chart.
        @Test
        public void chartDataPoint() throws Exception {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
        
            Shape shape = builder.insertChart(ChartType.LINE, 500.0, 350.0);
            Chart chart = shape.getChart();
        
            Assert.assertEquals(3, chart.getSeries().getCount());
            Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
            Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
            Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
        
            // Emphasize the chart's data points by making them appear as diamond shapes.
            for (ChartSeries series : chart.getSeries()) 
                applyDataPoints(series, 4, MarkerSymbol.DIAMOND, 15);
        
            // Smooth out the line that represents the first data series.
            chart.getSeries().get(0).setSmooth(true);
        
            // Verify that data points for the first series will not invert their colors if the value is negative.
            Iterator<ChartDataPoint> enumerator = chart.getSeries().get(0).getDataPoints().iterator();
            while (enumerator.hasNext()) {
                Assert.assertFalse(enumerator.next().getInvertIfNegative());
            }
        
            // For a cleaner looking graph, we can remove data points individually.
            chart.getSeries().get(1).getDataPoints().removeAt(2);
        
            // We can also strip an entire series of data points at once.
            chart.getSeries().get(2).getDataPoints().clear();
        
            doc.save(getArtifactsDir() + "Charts.ChartDataPoint.docx");
        }
        
        /// <summary>
        /// Applies a number of data points to a series.
        /// </summary>
        private static void applyDataPoints(ChartSeries series, int dataPointsCount, 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);
            }
        }