ChartXValueCollection
Inheritance: java.lang.Object
All Implemented Interfaces: java.lang.Iterable
public class ChartXValueCollection implements Iterable
Represents a collection of X values for a chart series.
Remarks:
All items of the collection other than null must have the same ChartXValue.getValueType().
The collection allows only changing X values. To add or insert new values to a chart series, or remove values, the appropriate methods of the ChartSeries class can be used.
Examples:
Shows how to get chart series data.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder();
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
Chart chart = shape.getChart();
ChartSeries series = chart.getSeries().get(0);
double minValue = Double.MAX_VALUE;
int minValueIndex = 0;
double maxValue = -Double.MAX_VALUE;
int maxValueIndex = 0;
for (int i = 0; i < series.getYValues().getCount(); i++)
{
// Clear individual format of all data points.
// Data points and data values are one-to-one in column charts.
series.getDataPoints().get(i).clearFormat();
// Get Y value.
double yValue = series.getYValues().get(i).getDoubleValue();
if (yValue < minValue)
{
minValue = yValue;
minValueIndex = i;
}
if (yValue > maxValue)
{
maxValue = yValue;
maxValueIndex = i;
}
}
// Change colors of the max and min values.
series.getDataPoints().get(minValueIndex).getFormat().getFill().setForeColor(Color.RED);
series.getDataPoints().get(maxValueIndex).getFormat().getFill().setForeColor(Color.GREEN);
doc.save(getArtifactsDir() + "Charts.GetChartSeriesData.docx");
Methods
Method | Description |
---|---|
get(int index) | Gets the X value at the specified index. |
getCount() | Gets the number of items in this collection. |
getFormatCode() | Gets the format code applied to the X values. |
iterator() | Returns an enumerator object. |
set(int index, ChartXValue value) | Sets the X value at the specified index. |
setFormatCode(String value) | Sets the format code applied to the X values. |
get(int index)
public ChartXValue get(int index)
Gets the X value at the specified index.
Remarks:
Empty values are represented as null.
Parameters:
Parameter | Type | Description |
---|---|---|
index | int |
Returns: ChartXValue - The X value at the specified index.
getCount()
public int getCount()
Gets the number of items in this collection.
Returns: int - The number of items in this collection.
getFormatCode()
public String getFormatCode()
Gets the format code applied to the X values.
Remarks:
Number formatting is used to change the way values appears in the chart. The examples of number formats:
Number - “#,##0.00”
Currency - “\"$\”#,##0.00"
Time - “[$-x-systime]h:mm:ss AM/PM”
Date - “d/mm/yyyy”
Percentage - “0.00%”
Fraction - “# ?/?”
Scientific - “0.00E+00”
Accounting - “_-\"$\”* #,##0.00_-;-\"$\"* #,##0.00_-;_-\"$\"* \"-\"??_-;_-@_-"
Custom with color - “[Red]-#,##0.0”
Examples:
Shows how to work with the format code of the chart data.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a Bubble chart.
Shape shape = builder.insertChart(ChartType.BUBBLE, 432.0, 252.0);
Chart chart = shape.getChart();
// Delete default generated series.
chart.getSeries().clear();
ChartSeries series = chart.getSeries().add(
"Series1",
new double[] { 1.0, 1.9, 2.45, 3.0 },
new double[] { 1.0, -0.9, 1.82, 0.0 },
new double[] { 2.0, 1.1, 2.95, 2.0 });
// Show data labels.
series.hasDataLabels(true);
series.getDataLabels().setShowCategoryName(true);
series.getDataLabels().setShowValue(true);
series.getDataLabels().setShowBubbleSize(true);
// Set data format codes.
series.getXValues().setFormatCode("#,##0.0#");
series.getYValues().setFormatCode("#,##0.0#;[Red]\\-#,##0.0#");
series.getBubbleSizes().setFormatCode("#,##0.0#");
doc.save(getArtifactsDir() + "Charts.FormatCode.docx");
Returns: java.lang.String - The format code applied to the X values.
iterator()
public Iterator iterator()
Returns an enumerator object.
Returns: java.util.Iterator
set(int index, ChartXValue value)
public void set(int index, ChartXValue value)
Sets the X value at the specified index.
Remarks:
Empty values are represented as null.
Parameters:
Parameter | Type | Description |
---|---|---|
index | int | |
value | ChartXValue | The X value at the specified index. |
setFormatCode(String value)
public void setFormatCode(String value)
Sets the format code applied to the X values.
Remarks:
Number formatting is used to change the way values appears in the chart. The examples of number formats:
Number - “#,##0.00”
Currency - “\"$\”#,##0.00"
Time - “[$-x-systime]h:mm:ss AM/PM”
Date - “d/mm/yyyy”
Percentage - “0.00%”
Fraction - “# ?/?”
Scientific - “0.00E+00”
Accounting - “_-\"$\”* #,##0.00_-;-\"$\"* #,##0.00_-;_-\"$\"* \"-\"??_-;_-@_-"
Custom with color - “[Red]-#,##0.0”
Examples:
Shows how to work with the format code of the chart data.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a Bubble chart.
Shape shape = builder.insertChart(ChartType.BUBBLE, 432.0, 252.0);
Chart chart = shape.getChart();
// Delete default generated series.
chart.getSeries().clear();
ChartSeries series = chart.getSeries().add(
"Series1",
new double[] { 1.0, 1.9, 2.45, 3.0 },
new double[] { 1.0, -0.9, 1.82, 0.0 },
new double[] { 2.0, 1.1, 2.95, 2.0 });
// Show data labels.
series.hasDataLabels(true);
series.getDataLabels().setShowCategoryName(true);
series.getDataLabels().setShowValue(true);
series.getDataLabels().setShowBubbleSize(true);
// Set data format codes.
series.getXValues().setFormatCode("#,##0.0#");
series.getYValues().setFormatCode("#,##0.0#;[Red]\\-#,##0.0#");
series.getBubbleSizes().setFormatCode("#,##0.0#");
doc.save(getArtifactsDir() + "Charts.FormatCode.docx");
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.lang.String | The format code applied to the X values. |