com.aspose.words

Class ChartSeriesCollection

  • java.lang.Object
    • com.aspose.words.ChartSeriesCollection
  • All Implemented Interfaces:
    java.lang.Iterable
    public class ChartSeriesCollection 
    extends java.lang.Object

Represents collection of a ChartSeries.

Example:

Shows how to add and remove series data in a chart.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a column chart that will contain three series of demo data by default.
Shape chartShape = builder.insertChart(ChartType.COLUMN, 400.0, 300.0);
Chart chart = chartShape.getChart();

// Each series has four decimal values: one for each of the four categories.
// Four clusters of three columns will represent this data.
ChartSeriesCollection chartData = chart.getSeries();

Assert.assertEquals(3, chartData.getCount());

// Print the name of every series in the chart.
Iterator<ChartSeries> enumerator = chart.getSeries().iterator();
while (enumerator.hasNext()) {
    System.out.println(enumerator.next().getName());
}

// These are the names of the categories in the chart.
String[] categories = {"Category 1", "Category 2", "Category 3", "Category 4"};

// We can add a series with new values for existing categories.
// This chart will now contain four clusters of four columns.
chart.getSeries().add("Series 4", categories, new double[]{4.4, 7.0, 3.5, 2.1});

// A chart series can also be removed by index, like this.
// This will remove one of the three demo series that came with the chart.
chartData.removeAt(2);

Assert.assertFalse(IterableUtils.matchesAny(chartData, s -> s.getName() == "Series 3"));

// We can also clear all the chart's data at once with this method.
// When creating a new chart, this is the way to wipe all the demo data
// before we can begin working on a blank chart.
chartData.clear();

Property Getters/Setters Summary
intgetCount()
Returns the number of ChartSeries in this collection.
ChartSeriesget(int index)
Returns a ChartSeries at the specified index.
 
Method Summary
ChartSeriesadd(java.lang.String seriesName, double[] xValues, double[] yValues)
Adds new ChartSeries to this collection. Use this method to add series to any type of Scatter charts.
ChartSeriesadd(java.lang.String seriesName, double[] xValues, double[] yValues, double[] bubbleSizes)
Adds new ChartSeries to this collection. Use this method to add series to any type of Bubble charts.
ChartSeriesadd(java.lang.String seriesName, java.lang.String[] categories, double[] values)
Adds new ChartSeries to this collection. Use this method to add series to any type of Bar, Column, Line and Surface charts.
ChartSeriesadd(java.lang.String seriesName, java.util.Date[] dates, double[] values)
Adds new ChartSeries to this collection. Use this method to add series to any type of Area, Radar and Stock charts.
voidclear()
Removes all ChartSeries from this collection.
java.util.Iterator<ChartSeries>iterator()
Returns an enumerator object.
voidremoveAt(int index)
Removes a ChartSeries at the specified index.
 

    • Property Getters/Setters Detail

      • getCount

        public int getCount()
        
        Returns the number of ChartSeries in this collection.

        Example:

        Shows how to add and remove series data in a chart.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a column chart that will contain three series of demo data by default.
        Shape chartShape = builder.insertChart(ChartType.COLUMN, 400.0, 300.0);
        Chart chart = chartShape.getChart();
        
        // Each series has four decimal values: one for each of the four categories.
        // Four clusters of three columns will represent this data.
        ChartSeriesCollection chartData = chart.getSeries();
        
        Assert.assertEquals(3, chartData.getCount());
        
        // Print the name of every series in the chart.
        Iterator<ChartSeries> enumerator = chart.getSeries().iterator();
        while (enumerator.hasNext()) {
            System.out.println(enumerator.next().getName());
        }
        
        // These are the names of the categories in the chart.
        String[] categories = {"Category 1", "Category 2", "Category 3", "Category 4"};
        
        // We can add a series with new values for existing categories.
        // This chart will now contain four clusters of four columns.
        chart.getSeries().add("Series 4", categories, new double[]{4.4, 7.0, 3.5, 2.1});
        
        // A chart series can also be removed by index, like this.
        // This will remove one of the three demo series that came with the chart.
        chartData.removeAt(2);
        
        Assert.assertFalse(IterableUtils.matchesAny(chartData, s -> s.getName() == "Series 3"));
        
        // We can also clear all the chart's data at once with this method.
        // When creating a new chart, this is the way to wipe all the demo data
        // before we can begin working on a blank chart.
        chartData.clear();
      • get

        public ChartSeries get(int index)
        
        Returns a ChartSeries at the specified index.

        The index is zero-based.

        Negative indexes are allowed and indicate access from the back of the collection. For example -1 means the last item, -2 means the second before last and so on.

        If index is greater than or equal to the number of items in the list, this returns a null reference.

        If index is negative and its absolute value is greater than the number of items in the list, this returns a null reference.

        Parameters:
        index - An index into the collection.

        Example:

        Shows how to add and remove series data in a chart.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a column chart that will contain three series of demo data by default.
        Shape chartShape = builder.insertChart(ChartType.COLUMN, 400.0, 300.0);
        Chart chart = chartShape.getChart();
        
        // Each series has four decimal values: one for each of the four categories.
        // Four clusters of three columns will represent this data.
        ChartSeriesCollection chartData = chart.getSeries();
        
        Assert.assertEquals(3, chartData.getCount());
        
        // Print the name of every series in the chart.
        Iterator<ChartSeries> enumerator = chart.getSeries().iterator();
        while (enumerator.hasNext()) {
            System.out.println(enumerator.next().getName());
        }
        
        // These are the names of the categories in the chart.
        String[] categories = {"Category 1", "Category 2", "Category 3", "Category 4"};
        
        // We can add a series with new values for existing categories.
        // This chart will now contain four clusters of four columns.
        chart.getSeries().add("Series 4", categories, new double[]{4.4, 7.0, 3.5, 2.1});
        
        // A chart series can also be removed by index, like this.
        // This will remove one of the three demo series that came with the chart.
        chartData.removeAt(2);
        
        Assert.assertFalse(IterableUtils.matchesAny(chartData, s -> s.getName() == "Series 3"));
        
        // We can also clear all the chart's data at once with this method.
        // When creating a new chart, this is the way to wipe all the demo data
        // before we can begin working on a blank chart.
        chartData.clear();
    • Method Detail

      • add

        public ChartSeries add(java.lang.String seriesName, double[] xValues, double[] yValues)
        Adds new ChartSeries to this collection. Use this method to add series to any type of Scatter charts.
        Returns:
        Recently added ChartSeries object.

        Example:

        Shows how to create an appropriate type of chart series for a graph type.
        public void chartSeriesCollection() throws Exception {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
        
            // There are several ways of populating a chart's series collection.
            // Different series schemas are intended for different chart types.
            // 1 -  Column chart with columns grouped and banded along the X-axis by category:
            Chart chart = appendChart(builder, ChartType.COLUMN, 500.0, 300.0);
        
            String[] categories = {"Category 1", "Category 2", "Category 3"};
        
            // Insert two series of decimal values containing a value for each respective category.
            // This column chart will have three groups, each with two columns.
            chart.getSeries().add("Series 1", categories, new double[]{76.6, 82.1, 91.6});
            chart.getSeries().add("Series 2", categories, new double[]{64.2, 79.5, 94.0});
        
            // Categories are distributed along the X-axis, and values are distributed along the Y-axis.
            Assert.assertEquals(ChartAxisType.CATEGORY, chart.getAxisX().getType());
            Assert.assertEquals(ChartAxisType.VALUE, chart.getAxisY().getType());
        
            // 2 -  Area chart with dates distributed along the X-axis:
            chart = appendChart(builder, ChartType.AREA, 500.0, 300.0);
        
            Date[] dates = {DocumentHelper.createDate(2014, 3, 31),
                    DocumentHelper.createDate(2017, 1, 23),
                    DocumentHelper.createDate(2017, 6, 18),
                    DocumentHelper.createDate(2019, 11, 22),
                    DocumentHelper.createDate(2020, 9, 7)
            };
        
            // Insert a series with a decimal value for each respective date.
            // The dates will be distributed along a linear X-axis,
            // and the values added to this series will create data points.
            chart.getSeries().add("Series 1", dates, new double[]{15.8, 21.5, 22.9, 28.7, 33.1});
        
            Assert.assertEquals(ChartAxisType.CATEGORY, chart.getAxisX().getType());
            Assert.assertEquals(ChartAxisType.VALUE, chart.getAxisY().getType());
        
            // 3 -  2D scatter plot:
            chart = appendChart(builder, ChartType.SCATTER, 500.0, 300.0);
        
            // Each series will need two decimal arrays of equal length.
            // The first array contains X-values, and the second contains corresponding Y-values
            // of data points on the chart's graph.
            chart.getSeries().add("Series 1",
                    new double[]{3.1, 3.5, 6.3, 4.1, 2.2, 8.3, 1.2, 3.6},
                    new double[]{3.1, 6.3, 4.6, 0.9, 8.5, 4.2, 2.3, 9.9});
            chart.getSeries().add("Series 2",
                    new double[]{2.6, 7.3, 4.5, 6.6, 2.1, 9.3, 0.7, 3.3},
                    new double[]{7.1, 6.6, 3.5, 7.8, 7.7, 9.5, 1.3, 4.6});
        
            Assert.assertEquals(ChartAxisType.VALUE, chart.getAxisX().getType());
            Assert.assertEquals(ChartAxisType.VALUE, chart.getAxisY().getType());
        
            // 4 -  Bubble chart:
            chart = appendChart(builder, ChartType.BUBBLE, 500.0, 300.0);
        
            // Each series will need three decimal arrays of equal length.
            // The first array contains X-values, the second contains corresponding Y-values,
            // and the third contains diameters for each of the graph's data points.
            chart.getSeries().add("Series 1",
                    new double[]{1.1, 5.0, 9.8},
                    new double[]{1.2, 4.9, 9.9},
                    new double[]{2.0, 4.0, 8.0});
        
            doc.save(getArtifactsDir() + "Charts.ChartSeriesCollection.docx");
        }
        
        /// <summary>
        /// Insert a chart using a document builder of a specified ChartType, width and height, and remove its demo data.
        /// </summary>
        private static Chart appendChart(DocumentBuilder builder, /*ChartType*/int chartType, double width, double height) throws Exception {
            Shape chartShape = builder.insertChart(chartType, width, height);
            Chart chart = chartShape.getChart();
            chart.getSeries().clear();
        
            return chart;
        }
      • add

        public ChartSeries add(java.lang.String seriesName, double[] xValues, double[] yValues, double[] bubbleSizes)
        Adds new ChartSeries to this collection. Use this method to add series to any type of Bubble charts.
        Returns:
        Recently added ChartSeries object.

        Example:

        Shows how to create an appropriate type of chart series for a graph type.
        public void chartSeriesCollection() throws Exception {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
        
            // There are several ways of populating a chart's series collection.
            // Different series schemas are intended for different chart types.
            // 1 -  Column chart with columns grouped and banded along the X-axis by category:
            Chart chart = appendChart(builder, ChartType.COLUMN, 500.0, 300.0);
        
            String[] categories = {"Category 1", "Category 2", "Category 3"};
        
            // Insert two series of decimal values containing a value for each respective category.
            // This column chart will have three groups, each with two columns.
            chart.getSeries().add("Series 1", categories, new double[]{76.6, 82.1, 91.6});
            chart.getSeries().add("Series 2", categories, new double[]{64.2, 79.5, 94.0});
        
            // Categories are distributed along the X-axis, and values are distributed along the Y-axis.
            Assert.assertEquals(ChartAxisType.CATEGORY, chart.getAxisX().getType());
            Assert.assertEquals(ChartAxisType.VALUE, chart.getAxisY().getType());
        
            // 2 -  Area chart with dates distributed along the X-axis:
            chart = appendChart(builder, ChartType.AREA, 500.0, 300.0);
        
            Date[] dates = {DocumentHelper.createDate(2014, 3, 31),
                    DocumentHelper.createDate(2017, 1, 23),
                    DocumentHelper.createDate(2017, 6, 18),
                    DocumentHelper.createDate(2019, 11, 22),
                    DocumentHelper.createDate(2020, 9, 7)
            };
        
            // Insert a series with a decimal value for each respective date.
            // The dates will be distributed along a linear X-axis,
            // and the values added to this series will create data points.
            chart.getSeries().add("Series 1", dates, new double[]{15.8, 21.5, 22.9, 28.7, 33.1});
        
            Assert.assertEquals(ChartAxisType.CATEGORY, chart.getAxisX().getType());
            Assert.assertEquals(ChartAxisType.VALUE, chart.getAxisY().getType());
        
            // 3 -  2D scatter plot:
            chart = appendChart(builder, ChartType.SCATTER, 500.0, 300.0);
        
            // Each series will need two decimal arrays of equal length.
            // The first array contains X-values, and the second contains corresponding Y-values
            // of data points on the chart's graph.
            chart.getSeries().add("Series 1",
                    new double[]{3.1, 3.5, 6.3, 4.1, 2.2, 8.3, 1.2, 3.6},
                    new double[]{3.1, 6.3, 4.6, 0.9, 8.5, 4.2, 2.3, 9.9});
            chart.getSeries().add("Series 2",
                    new double[]{2.6, 7.3, 4.5, 6.6, 2.1, 9.3, 0.7, 3.3},
                    new double[]{7.1, 6.6, 3.5, 7.8, 7.7, 9.5, 1.3, 4.6});
        
            Assert.assertEquals(ChartAxisType.VALUE, chart.getAxisX().getType());
            Assert.assertEquals(ChartAxisType.VALUE, chart.getAxisY().getType());
        
            // 4 -  Bubble chart:
            chart = appendChart(builder, ChartType.BUBBLE, 500.0, 300.0);
        
            // Each series will need three decimal arrays of equal length.
            // The first array contains X-values, the second contains corresponding Y-values,
            // and the third contains diameters for each of the graph's data points.
            chart.getSeries().add("Series 1",
                    new double[]{1.1, 5.0, 9.8},
                    new double[]{1.2, 4.9, 9.9},
                    new double[]{2.0, 4.0, 8.0});
        
            doc.save(getArtifactsDir() + "Charts.ChartSeriesCollection.docx");
        }
        
        /// <summary>
        /// Insert a chart using a document builder of a specified ChartType, width and height, and remove its demo data.
        /// </summary>
        private static Chart appendChart(DocumentBuilder builder, /*ChartType*/int chartType, double width, double height) throws Exception {
            Shape chartShape = builder.insertChart(chartType, width, height);
            Chart chart = chartShape.getChart();
            chart.getSeries().clear();
        
            return chart;
        }
      • add

        public ChartSeries add(java.lang.String seriesName, java.lang.String[] categories, double[] values)
        Adds new ChartSeries to this collection. Use this method to add series to any type of Bar, Column, Line and Surface charts.
        Returns:
        Recently added ChartSeries object.

        Example:

        Shows how to create an appropriate type of chart series for a graph type.
        public void chartSeriesCollection() throws Exception {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
        
            // There are several ways of populating a chart's series collection.
            // Different series schemas are intended for different chart types.
            // 1 -  Column chart with columns grouped and banded along the X-axis by category:
            Chart chart = appendChart(builder, ChartType.COLUMN, 500.0, 300.0);
        
            String[] categories = {"Category 1", "Category 2", "Category 3"};
        
            // Insert two series of decimal values containing a value for each respective category.
            // This column chart will have three groups, each with two columns.
            chart.getSeries().add("Series 1", categories, new double[]{76.6, 82.1, 91.6});
            chart.getSeries().add("Series 2", categories, new double[]{64.2, 79.5, 94.0});
        
            // Categories are distributed along the X-axis, and values are distributed along the Y-axis.
            Assert.assertEquals(ChartAxisType.CATEGORY, chart.getAxisX().getType());
            Assert.assertEquals(ChartAxisType.VALUE, chart.getAxisY().getType());
        
            // 2 -  Area chart with dates distributed along the X-axis:
            chart = appendChart(builder, ChartType.AREA, 500.0, 300.0);
        
            Date[] dates = {DocumentHelper.createDate(2014, 3, 31),
                    DocumentHelper.createDate(2017, 1, 23),
                    DocumentHelper.createDate(2017, 6, 18),
                    DocumentHelper.createDate(2019, 11, 22),
                    DocumentHelper.createDate(2020, 9, 7)
            };
        
            // Insert a series with a decimal value for each respective date.
            // The dates will be distributed along a linear X-axis,
            // and the values added to this series will create data points.
            chart.getSeries().add("Series 1", dates, new double[]{15.8, 21.5, 22.9, 28.7, 33.1});
        
            Assert.assertEquals(ChartAxisType.CATEGORY, chart.getAxisX().getType());
            Assert.assertEquals(ChartAxisType.VALUE, chart.getAxisY().getType());
        
            // 3 -  2D scatter plot:
            chart = appendChart(builder, ChartType.SCATTER, 500.0, 300.0);
        
            // Each series will need two decimal arrays of equal length.
            // The first array contains X-values, and the second contains corresponding Y-values
            // of data points on the chart's graph.
            chart.getSeries().add("Series 1",
                    new double[]{3.1, 3.5, 6.3, 4.1, 2.2, 8.3, 1.2, 3.6},
                    new double[]{3.1, 6.3, 4.6, 0.9, 8.5, 4.2, 2.3, 9.9});
            chart.getSeries().add("Series 2",
                    new double[]{2.6, 7.3, 4.5, 6.6, 2.1, 9.3, 0.7, 3.3},
                    new double[]{7.1, 6.6, 3.5, 7.8, 7.7, 9.5, 1.3, 4.6});
        
            Assert.assertEquals(ChartAxisType.VALUE, chart.getAxisX().getType());
            Assert.assertEquals(ChartAxisType.VALUE, chart.getAxisY().getType());
        
            // 4 -  Bubble chart:
            chart = appendChart(builder, ChartType.BUBBLE, 500.0, 300.0);
        
            // Each series will need three decimal arrays of equal length.
            // The first array contains X-values, the second contains corresponding Y-values,
            // and the third contains diameters for each of the graph's data points.
            chart.getSeries().add("Series 1",
                    new double[]{1.1, 5.0, 9.8},
                    new double[]{1.2, 4.9, 9.9},
                    new double[]{2.0, 4.0, 8.0});
        
            doc.save(getArtifactsDir() + "Charts.ChartSeriesCollection.docx");
        }
        
        /// <summary>
        /// Insert a chart using a document builder of a specified ChartType, width and height, and remove its demo data.
        /// </summary>
        private static Chart appendChart(DocumentBuilder builder, /*ChartType*/int chartType, double width, double height) throws Exception {
            Shape chartShape = builder.insertChart(chartType, width, height);
            Chart chart = chartShape.getChart();
            chart.getSeries().clear();
        
            return chart;
        }
      • add

        public ChartSeries add(java.lang.String seriesName, java.util.Date[] dates, double[] values)
        Adds new ChartSeries to this collection. Use this method to add series to any type of Area, Radar and Stock charts.

        Example:

        Shows how to create an appropriate type of chart series for a graph type.
        public void chartSeriesCollection() throws Exception {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
        
            // There are several ways of populating a chart's series collection.
            // Different series schemas are intended for different chart types.
            // 1 -  Column chart with columns grouped and banded along the X-axis by category:
            Chart chart = appendChart(builder, ChartType.COLUMN, 500.0, 300.0);
        
            String[] categories = {"Category 1", "Category 2", "Category 3"};
        
            // Insert two series of decimal values containing a value for each respective category.
            // This column chart will have three groups, each with two columns.
            chart.getSeries().add("Series 1", categories, new double[]{76.6, 82.1, 91.6});
            chart.getSeries().add("Series 2", categories, new double[]{64.2, 79.5, 94.0});
        
            // Categories are distributed along the X-axis, and values are distributed along the Y-axis.
            Assert.assertEquals(ChartAxisType.CATEGORY, chart.getAxisX().getType());
            Assert.assertEquals(ChartAxisType.VALUE, chart.getAxisY().getType());
        
            // 2 -  Area chart with dates distributed along the X-axis:
            chart = appendChart(builder, ChartType.AREA, 500.0, 300.0);
        
            Date[] dates = {DocumentHelper.createDate(2014, 3, 31),
                    DocumentHelper.createDate(2017, 1, 23),
                    DocumentHelper.createDate(2017, 6, 18),
                    DocumentHelper.createDate(2019, 11, 22),
                    DocumentHelper.createDate(2020, 9, 7)
            };
        
            // Insert a series with a decimal value for each respective date.
            // The dates will be distributed along a linear X-axis,
            // and the values added to this series will create data points.
            chart.getSeries().add("Series 1", dates, new double[]{15.8, 21.5, 22.9, 28.7, 33.1});
        
            Assert.assertEquals(ChartAxisType.CATEGORY, chart.getAxisX().getType());
            Assert.assertEquals(ChartAxisType.VALUE, chart.getAxisY().getType());
        
            // 3 -  2D scatter plot:
            chart = appendChart(builder, ChartType.SCATTER, 500.0, 300.0);
        
            // Each series will need two decimal arrays of equal length.
            // The first array contains X-values, and the second contains corresponding Y-values
            // of data points on the chart's graph.
            chart.getSeries().add("Series 1",
                    new double[]{3.1, 3.5, 6.3, 4.1, 2.2, 8.3, 1.2, 3.6},
                    new double[]{3.1, 6.3, 4.6, 0.9, 8.5, 4.2, 2.3, 9.9});
            chart.getSeries().add("Series 2",
                    new double[]{2.6, 7.3, 4.5, 6.6, 2.1, 9.3, 0.7, 3.3},
                    new double[]{7.1, 6.6, 3.5, 7.8, 7.7, 9.5, 1.3, 4.6});
        
            Assert.assertEquals(ChartAxisType.VALUE, chart.getAxisX().getType());
            Assert.assertEquals(ChartAxisType.VALUE, chart.getAxisY().getType());
        
            // 4 -  Bubble chart:
            chart = appendChart(builder, ChartType.BUBBLE, 500.0, 300.0);
        
            // Each series will need three decimal arrays of equal length.
            // The first array contains X-values, the second contains corresponding Y-values,
            // and the third contains diameters for each of the graph's data points.
            chart.getSeries().add("Series 1",
                    new double[]{1.1, 5.0, 9.8},
                    new double[]{1.2, 4.9, 9.9},
                    new double[]{2.0, 4.0, 8.0});
        
            doc.save(getArtifactsDir() + "Charts.ChartSeriesCollection.docx");
        }
        
        /// <summary>
        /// Insert a chart using a document builder of a specified ChartType, width and height, and remove its demo data.
        /// </summary>
        private static Chart appendChart(DocumentBuilder builder, /*ChartType*/int chartType, double width, double height) throws Exception {
            Shape chartShape = builder.insertChart(chartType, width, height);
            Chart chart = chartShape.getChart();
            chart.getSeries().clear();
        
            return chart;
        }
      • clear

        public void clear()
        Removes all ChartSeries from this collection.

        Example:

        Shows how to add and remove series data in a chart.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a column chart that will contain three series of demo data by default.
        Shape chartShape = builder.insertChart(ChartType.COLUMN, 400.0, 300.0);
        Chart chart = chartShape.getChart();
        
        // Each series has four decimal values: one for each of the four categories.
        // Four clusters of three columns will represent this data.
        ChartSeriesCollection chartData = chart.getSeries();
        
        Assert.assertEquals(3, chartData.getCount());
        
        // Print the name of every series in the chart.
        Iterator<ChartSeries> enumerator = chart.getSeries().iterator();
        while (enumerator.hasNext()) {
            System.out.println(enumerator.next().getName());
        }
        
        // These are the names of the categories in the chart.
        String[] categories = {"Category 1", "Category 2", "Category 3", "Category 4"};
        
        // We can add a series with new values for existing categories.
        // This chart will now contain four clusters of four columns.
        chart.getSeries().add("Series 4", categories, new double[]{4.4, 7.0, 3.5, 2.1});
        
        // A chart series can also be removed by index, like this.
        // This will remove one of the three demo series that came with the chart.
        chartData.removeAt(2);
        
        Assert.assertFalse(IterableUtils.matchesAny(chartData, s -> s.getName() == "Series 3"));
        
        // We can also clear all the chart's data at once with this method.
        // When creating a new chart, this is the way to wipe all the demo data
        // before we can begin working on a blank chart.
        chartData.clear();
      • iterator

        public java.util.Iterator<ChartSeries> iterator()
        Returns an enumerator object.

        Example:

        Shows how to add and remove series data in a chart.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a column chart that will contain three series of demo data by default.
        Shape chartShape = builder.insertChart(ChartType.COLUMN, 400.0, 300.0);
        Chart chart = chartShape.getChart();
        
        // Each series has four decimal values: one for each of the four categories.
        // Four clusters of three columns will represent this data.
        ChartSeriesCollection chartData = chart.getSeries();
        
        Assert.assertEquals(3, chartData.getCount());
        
        // Print the name of every series in the chart.
        Iterator<ChartSeries> enumerator = chart.getSeries().iterator();
        while (enumerator.hasNext()) {
            System.out.println(enumerator.next().getName());
        }
        
        // These are the names of the categories in the chart.
        String[] categories = {"Category 1", "Category 2", "Category 3", "Category 4"};
        
        // We can add a series with new values for existing categories.
        // This chart will now contain four clusters of four columns.
        chart.getSeries().add("Series 4", categories, new double[]{4.4, 7.0, 3.5, 2.1});
        
        // A chart series can also be removed by index, like this.
        // This will remove one of the three demo series that came with the chart.
        chartData.removeAt(2);
        
        Assert.assertFalse(IterableUtils.matchesAny(chartData, s -> s.getName() == "Series 3"));
        
        // We can also clear all the chart's data at once with this method.
        // When creating a new chart, this is the way to wipe all the demo data
        // before we can begin working on a blank chart.
        chartData.clear();
      • removeAt

        public void removeAt(int index)
        Removes a ChartSeries at the specified index.
        Parameters:
        index - The zero-based index of the ChartSeries to remove.

        Example:

        Shows how to add and remove series data in a chart.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a column chart that will contain three series of demo data by default.
        Shape chartShape = builder.insertChart(ChartType.COLUMN, 400.0, 300.0);
        Chart chart = chartShape.getChart();
        
        // Each series has four decimal values: one for each of the four categories.
        // Four clusters of three columns will represent this data.
        ChartSeriesCollection chartData = chart.getSeries();
        
        Assert.assertEquals(3, chartData.getCount());
        
        // Print the name of every series in the chart.
        Iterator<ChartSeries> enumerator = chart.getSeries().iterator();
        while (enumerator.hasNext()) {
            System.out.println(enumerator.next().getName());
        }
        
        // These are the names of the categories in the chart.
        String[] categories = {"Category 1", "Category 2", "Category 3", "Category 4"};
        
        // We can add a series with new values for existing categories.
        // This chart will now contain four clusters of four columns.
        chart.getSeries().add("Series 4", categories, new double[]{4.4, 7.0, 3.5, 2.1});
        
        // A chart series can also be removed by index, like this.
        // This will remove one of the three demo series that came with the chart.
        chartData.removeAt(2);
        
        Assert.assertFalse(IterableUtils.matchesAny(chartData, s -> s.getName() == "Series 3"));
        
        // We can also clear all the chart's data at once with this method.
        // When creating a new chart, this is the way to wipe all the demo data
        // before we can begin working on a blank chart.
        chartData.clear();