java.lang.Object
com.aspose.words.ChartSeriesCollection
public class ChartSeriesCollection
Example:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a bar chart
Shape chartShape = builder.insertChart(ChartType.COLUMN, 400.0, 300.0);
Chart chart = chartShape.getChart();
// All charts come with demo data
// This column chart currently has 3 series with 4 categories, which means 4 clusters, 3 columns in each
ChartSeriesCollection chartData = chart.getSeries();
Assert.assertEquals(chartData.getCount(), 3);
// Iterate through the series with an enumerator and print their names
Iterator<ChartSeries> enumerator = chart.getSeries().iterator();
// And use it to go over all the data labels in one series and change their separator
while (enumerator.hasNext()) {
System.out.println(enumerator.next().getName());
}
// We can add new data by adding a new series to the collection, with categories and data
// We will match the existing category/series names in the demo data and add a 4th column to each column cluster
String[] categories = {"Category 1", "Category 2", "Category 3", "Category 4"};
chart.getSeries().add("Series 4", categories, new double[]{4.4, 7.0, 3.5, 2.1});
Assert.assertEquals(chartData.getCount(), 4);
Assert.assertEquals(chartData.get(3).getName(), "Series 4");
// We can remove series by index
chartData.removeAt(2);
Assert.assertEquals(chartData.getCount(), 3);
Assert.assertEquals(chartData.get(2).getName(), "Series 4");
// We can also remove out all the series
// This leaves us with an empty graph and is a convenient way of wiping out demo data
chartData.clear();
Assert.assertEquals(0, chartData.getCount());
| Property Getters/Setters Summary | ||
|---|---|---|
int | getCount() | |
|
Returns the number of |
||
ChartSeries | get(int index) | |
|
Returns a |
||
| Method Summary | ||
|---|---|---|
ChartSeries | add(java.lang.String seriesName, double[] xValues, double[] yValues) | |
|
Adds new |
||
ChartSeries | add(java.lang.String seriesName, double[] xValues, double[] yValues, double[] bubbleSizes) | |
|
Adds new |
||
ChartSeries | add(java.lang.String seriesName, java.lang.String[] categories, double[] values) | |
|
Adds new |
||
ChartSeries | add(java.lang.String seriesName, java.util.Date[] dates, double[] values) | |
|
Adds new |
||
void | clear() | |
|
Removes all |
||
java.util.Iterator<ChartSeries> | iterator() | |
| Returns an enumerator object. | ||
void | removeAt(int index) | |
|
Removes a |
||
| Property Getters/Setters Detail |
|---|
getCount | |
public int getCount() | |
Example:
Shows how to work with a chart's data collection.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a bar chart
Shape chartShape = builder.insertChart(ChartType.COLUMN, 400.0, 300.0);
Chart chart = chartShape.getChart();
// All charts come with demo data
// This column chart currently has 3 series with 4 categories, which means 4 clusters, 3 columns in each
ChartSeriesCollection chartData = chart.getSeries();
Assert.assertEquals(chartData.getCount(), 3);
// Iterate through the series with an enumerator and print their names
Iterator<ChartSeries> enumerator = chart.getSeries().iterator();
// And use it to go over all the data labels in one series and change their separator
while (enumerator.hasNext()) {
System.out.println(enumerator.next().getName());
}
// We can add new data by adding a new series to the collection, with categories and data
// We will match the existing category/series names in the demo data and add a 4th column to each column cluster
String[] categories = {"Category 1", "Category 2", "Category 3", "Category 4"};
chart.getSeries().add("Series 4", categories, new double[]{4.4, 7.0, 3.5, 2.1});
Assert.assertEquals(chartData.getCount(), 4);
Assert.assertEquals(chartData.get(3).getName(), "Series 4");
// We can remove series by index
chartData.removeAt(2);
Assert.assertEquals(chartData.getCount(), 3);
Assert.assertEquals(chartData.get(2).getName(), "Series 4");
// We can also remove out all the series
// This leaves us with an empty graph and is a convenient way of wiping out demo data
chartData.clear();
Assert.assertEquals(0, chartData.getCount());get | |
public ChartSeries get(int 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.
index - An index into the collection.Example:
Shows how to work with a chart's data collection.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a bar chart
Shape chartShape = builder.insertChart(ChartType.COLUMN, 400.0, 300.0);
Chart chart = chartShape.getChart();
// All charts come with demo data
// This column chart currently has 3 series with 4 categories, which means 4 clusters, 3 columns in each
ChartSeriesCollection chartData = chart.getSeries();
Assert.assertEquals(chartData.getCount(), 3);
// Iterate through the series with an enumerator and print their names
Iterator<ChartSeries> enumerator = chart.getSeries().iterator();
// And use it to go over all the data labels in one series and change their separator
while (enumerator.hasNext()) {
System.out.println(enumerator.next().getName());
}
// We can add new data by adding a new series to the collection, with categories and data
// We will match the existing category/series names in the demo data and add a 4th column to each column cluster
String[] categories = {"Category 1", "Category 2", "Category 3", "Category 4"};
chart.getSeries().add("Series 4", categories, new double[]{4.4, 7.0, 3.5, 2.1});
Assert.assertEquals(chartData.getCount(), 4);
Assert.assertEquals(chartData.get(3).getName(), "Series 4");
// We can remove series by index
chartData.removeAt(2);
Assert.assertEquals(chartData.getCount(), 3);
Assert.assertEquals(chartData.get(2).getName(), "Series 4");
// We can also remove out all the series
// This leaves us with an empty graph and is a convenient way of wiping out demo data
chartData.clear();
Assert.assertEquals(0, chartData.getCount());| Method Detail |
|---|
add | |
public ChartSeries add(java.lang.String seriesName, double[] xValues, double[] yValues) | |
Example:
Shows an appropriate graph type for each chart series.
public void chartSeriesCollection() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// There are 4 ways of populating a chart's series collection
// 1: Each series has a string array of categories, each with a corresponding data value
// Some of the other possible applications are bar, column, line and surface charts
Chart chart = appendChart(builder, ChartType.COLUMN, 300.0, 300.0);
// Create and name 3 categories with a string array
String[] categories = {"Category 1", "Category 2", "Category 3"};
// Create 2 series of data, each with one point for every category
// This will generate a column graph with 3 clusters of 2 bars
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 while values are distributed along the Y-axis
Assert.assertEquals(chart.getAxisX().getType(), ChartAxisType.CATEGORY);
Assert.assertEquals(chart.getAxisY().getType(), ChartAxisType.VALUE);
// 2: Each series will have a collection of dates with a corresponding value for each date
// Area, radar and stock charts are some of the appropriate chart types for this
chart = appendChart(builder, ChartType.AREA, 300.0, 300.0);
// Create a collection of dates to serve as categories
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)
};
// Add one series with one point for each date
// Our sporadic dates will be distributed along the X-axis in a linear fashion
chart.getSeries().add("Series 1", dates, new double[]{15.8, 21.5, 22.9, 28.7, 33.1});
// 3: Each series will take two data arrays
// Appropriate for scatter plots
chart = appendChart(builder, ChartType.SCATTER, 300.0, 300.0);
// In each series, the first array contains the X-coordinates and the second contains respective Y-coordinates of points
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});
// Both axes are value axes in this case
Assert.assertEquals(chart.getAxisX().getType(), ChartAxisType.VALUE);
Assert.assertEquals(chart.getAxisY().getType(), ChartAxisType.VALUE);
// 4: Each series will be built from three data arrays, used for bubble charts
chart = appendChart(builder, ChartType.BUBBLE, 300.0, 300.0);
// The first two arrays contain X/Y coordinates like above and the third determines the thickness of each point
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>
/// Get the DocumentBuilder to insert a chart of a specified ChartType, width and height and clean out its default data
/// </summary>
private 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();
Assert.assertEquals(chart.getSeries().getCount(), 0);
return chart;
}add | |
public ChartSeries add(java.lang.String seriesName, double[] xValues, double[] yValues, double[] bubbleSizes) | |
Example:
Shows an appropriate graph type for each chart series.
public void chartSeriesCollection() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// There are 4 ways of populating a chart's series collection
// 1: Each series has a string array of categories, each with a corresponding data value
// Some of the other possible applications are bar, column, line and surface charts
Chart chart = appendChart(builder, ChartType.COLUMN, 300.0, 300.0);
// Create and name 3 categories with a string array
String[] categories = {"Category 1", "Category 2", "Category 3"};
// Create 2 series of data, each with one point for every category
// This will generate a column graph with 3 clusters of 2 bars
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 while values are distributed along the Y-axis
Assert.assertEquals(chart.getAxisX().getType(), ChartAxisType.CATEGORY);
Assert.assertEquals(chart.getAxisY().getType(), ChartAxisType.VALUE);
// 2: Each series will have a collection of dates with a corresponding value for each date
// Area, radar and stock charts are some of the appropriate chart types for this
chart = appendChart(builder, ChartType.AREA, 300.0, 300.0);
// Create a collection of dates to serve as categories
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)
};
// Add one series with one point for each date
// Our sporadic dates will be distributed along the X-axis in a linear fashion
chart.getSeries().add("Series 1", dates, new double[]{15.8, 21.5, 22.9, 28.7, 33.1});
// 3: Each series will take two data arrays
// Appropriate for scatter plots
chart = appendChart(builder, ChartType.SCATTER, 300.0, 300.0);
// In each series, the first array contains the X-coordinates and the second contains respective Y-coordinates of points
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});
// Both axes are value axes in this case
Assert.assertEquals(chart.getAxisX().getType(), ChartAxisType.VALUE);
Assert.assertEquals(chart.getAxisY().getType(), ChartAxisType.VALUE);
// 4: Each series will be built from three data arrays, used for bubble charts
chart = appendChart(builder, ChartType.BUBBLE, 300.0, 300.0);
// The first two arrays contain X/Y coordinates like above and the third determines the thickness of each point
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>
/// Get the DocumentBuilder to insert a chart of a specified ChartType, width and height and clean out its default data
/// </summary>
private 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();
Assert.assertEquals(chart.getSeries().getCount(), 0);
return chart;
}add | |
public ChartSeries add(java.lang.String seriesName, java.lang.String[] categories, double[] values) | |
Example:
Shows an appropriate graph type for each chart series.
public void chartSeriesCollection() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// There are 4 ways of populating a chart's series collection
// 1: Each series has a string array of categories, each with a corresponding data value
// Some of the other possible applications are bar, column, line and surface charts
Chart chart = appendChart(builder, ChartType.COLUMN, 300.0, 300.0);
// Create and name 3 categories with a string array
String[] categories = {"Category 1", "Category 2", "Category 3"};
// Create 2 series of data, each with one point for every category
// This will generate a column graph with 3 clusters of 2 bars
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 while values are distributed along the Y-axis
Assert.assertEquals(chart.getAxisX().getType(), ChartAxisType.CATEGORY);
Assert.assertEquals(chart.getAxisY().getType(), ChartAxisType.VALUE);
// 2: Each series will have a collection of dates with a corresponding value for each date
// Area, radar and stock charts are some of the appropriate chart types for this
chart = appendChart(builder, ChartType.AREA, 300.0, 300.0);
// Create a collection of dates to serve as categories
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)
};
// Add one series with one point for each date
// Our sporadic dates will be distributed along the X-axis in a linear fashion
chart.getSeries().add("Series 1", dates, new double[]{15.8, 21.5, 22.9, 28.7, 33.1});
// 3: Each series will take two data arrays
// Appropriate for scatter plots
chart = appendChart(builder, ChartType.SCATTER, 300.0, 300.0);
// In each series, the first array contains the X-coordinates and the second contains respective Y-coordinates of points
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});
// Both axes are value axes in this case
Assert.assertEquals(chart.getAxisX().getType(), ChartAxisType.VALUE);
Assert.assertEquals(chart.getAxisY().getType(), ChartAxisType.VALUE);
// 4: Each series will be built from three data arrays, used for bubble charts
chart = appendChart(builder, ChartType.BUBBLE, 300.0, 300.0);
// The first two arrays contain X/Y coordinates like above and the third determines the thickness of each point
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>
/// Get the DocumentBuilder to insert a chart of a specified ChartType, width and height and clean out its default data
/// </summary>
private 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();
Assert.assertEquals(chart.getSeries().getCount(), 0);
return chart;
}add | |
public ChartSeries add(java.lang.String seriesName, java.util.Date[] dates, double[] values) | |
Example:
Shows an appropriate graph type for each chart series.
public void chartSeriesCollection() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// There are 4 ways of populating a chart's series collection
// 1: Each series has a string array of categories, each with a corresponding data value
// Some of the other possible applications are bar, column, line and surface charts
Chart chart = appendChart(builder, ChartType.COLUMN, 300.0, 300.0);
// Create and name 3 categories with a string array
String[] categories = {"Category 1", "Category 2", "Category 3"};
// Create 2 series of data, each with one point for every category
// This will generate a column graph with 3 clusters of 2 bars
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 while values are distributed along the Y-axis
Assert.assertEquals(chart.getAxisX().getType(), ChartAxisType.CATEGORY);
Assert.assertEquals(chart.getAxisY().getType(), ChartAxisType.VALUE);
// 2: Each series will have a collection of dates with a corresponding value for each date
// Area, radar and stock charts are some of the appropriate chart types for this
chart = appendChart(builder, ChartType.AREA, 300.0, 300.0);
// Create a collection of dates to serve as categories
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)
};
// Add one series with one point for each date
// Our sporadic dates will be distributed along the X-axis in a linear fashion
chart.getSeries().add("Series 1", dates, new double[]{15.8, 21.5, 22.9, 28.7, 33.1});
// 3: Each series will take two data arrays
// Appropriate for scatter plots
chart = appendChart(builder, ChartType.SCATTER, 300.0, 300.0);
// In each series, the first array contains the X-coordinates and the second contains respective Y-coordinates of points
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});
// Both axes are value axes in this case
Assert.assertEquals(chart.getAxisX().getType(), ChartAxisType.VALUE);
Assert.assertEquals(chart.getAxisY().getType(), ChartAxisType.VALUE);
// 4: Each series will be built from three data arrays, used for bubble charts
chart = appendChart(builder, ChartType.BUBBLE, 300.0, 300.0);
// The first two arrays contain X/Y coordinates like above and the third determines the thickness of each point
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>
/// Get the DocumentBuilder to insert a chart of a specified ChartType, width and height and clean out its default data
/// </summary>
private 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();
Assert.assertEquals(chart.getSeries().getCount(), 0);
return chart;
}clear | |
public void clear() | |
Example:
Shows how to work with a chart's data collection.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a bar chart
Shape chartShape = builder.insertChart(ChartType.COLUMN, 400.0, 300.0);
Chart chart = chartShape.getChart();
// All charts come with demo data
// This column chart currently has 3 series with 4 categories, which means 4 clusters, 3 columns in each
ChartSeriesCollection chartData = chart.getSeries();
Assert.assertEquals(chartData.getCount(), 3);
// Iterate through the series with an enumerator and print their names
Iterator<ChartSeries> enumerator = chart.getSeries().iterator();
// And use it to go over all the data labels in one series and change their separator
while (enumerator.hasNext()) {
System.out.println(enumerator.next().getName());
}
// We can add new data by adding a new series to the collection, with categories and data
// We will match the existing category/series names in the demo data and add a 4th column to each column cluster
String[] categories = {"Category 1", "Category 2", "Category 3", "Category 4"};
chart.getSeries().add("Series 4", categories, new double[]{4.4, 7.0, 3.5, 2.1});
Assert.assertEquals(chartData.getCount(), 4);
Assert.assertEquals(chartData.get(3).getName(), "Series 4");
// We can remove series by index
chartData.removeAt(2);
Assert.assertEquals(chartData.getCount(), 3);
Assert.assertEquals(chartData.get(2).getName(), "Series 4");
// We can also remove out all the series
// This leaves us with an empty graph and is a convenient way of wiping out demo data
chartData.clear();
Assert.assertEquals(0, chartData.getCount());iterator | |
public java.util.Iterator<ChartSeries> iterator() | |
Example:
Shows how to work with a chart's data collection.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a bar chart
Shape chartShape = builder.insertChart(ChartType.COLUMN, 400.0, 300.0);
Chart chart = chartShape.getChart();
// All charts come with demo data
// This column chart currently has 3 series with 4 categories, which means 4 clusters, 3 columns in each
ChartSeriesCollection chartData = chart.getSeries();
Assert.assertEquals(chartData.getCount(), 3);
// Iterate through the series with an enumerator and print their names
Iterator<ChartSeries> enumerator = chart.getSeries().iterator();
// And use it to go over all the data labels in one series and change their separator
while (enumerator.hasNext()) {
System.out.println(enumerator.next().getName());
}
// We can add new data by adding a new series to the collection, with categories and data
// We will match the existing category/series names in the demo data and add a 4th column to each column cluster
String[] categories = {"Category 1", "Category 2", "Category 3", "Category 4"};
chart.getSeries().add("Series 4", categories, new double[]{4.4, 7.0, 3.5, 2.1});
Assert.assertEquals(chartData.getCount(), 4);
Assert.assertEquals(chartData.get(3).getName(), "Series 4");
// We can remove series by index
chartData.removeAt(2);
Assert.assertEquals(chartData.getCount(), 3);
Assert.assertEquals(chartData.get(2).getName(), "Series 4");
// We can also remove out all the series
// This leaves us with an empty graph and is a convenient way of wiping out demo data
chartData.clear();
Assert.assertEquals(0, chartData.getCount());removeAt | |
public void removeAt(int index) | |
index - The zero-based index of the ChartSeries to remove.Example:
Shows how to work with a chart's data collection.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a bar chart
Shape chartShape = builder.insertChart(ChartType.COLUMN, 400.0, 300.0);
Chart chart = chartShape.getChart();
// All charts come with demo data
// This column chart currently has 3 series with 4 categories, which means 4 clusters, 3 columns in each
ChartSeriesCollection chartData = chart.getSeries();
Assert.assertEquals(chartData.getCount(), 3);
// Iterate through the series with an enumerator and print their names
Iterator<ChartSeries> enumerator = chart.getSeries().iterator();
// And use it to go over all the data labels in one series and change their separator
while (enumerator.hasNext()) {
System.out.println(enumerator.next().getName());
}
// We can add new data by adding a new series to the collection, with categories and data
// We will match the existing category/series names in the demo data and add a 4th column to each column cluster
String[] categories = {"Category 1", "Category 2", "Category 3", "Category 4"};
chart.getSeries().add("Series 4", categories, new double[]{4.4, 7.0, 3.5, 2.1});
Assert.assertEquals(chartData.getCount(), 4);
Assert.assertEquals(chartData.get(3).getName(), "Series 4");
// We can remove series by index
chartData.removeAt(2);
Assert.assertEquals(chartData.getCount(), 3);
Assert.assertEquals(chartData.get(2).getName(), "Series 4");
// We can also remove out all the series
// This leaves us with an empty graph and is a convenient way of wiping out demo data
chartData.clear();
Assert.assertEquals(0, chartData.getCount());