ChartFormat
Inheritance: java.lang.Object
public class ChartFormat
Represents the formatting of a chart element.
To learn more, visit the Working with Charts documentation article.
Examples:
Shows how to use chart formating.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
Chart chart = shape.getChart();
// Delete series generated by default.
ChartSeriesCollection series = chart.getSeries();
series.clear();
String[] categories = new String[] { "Category 1", "Category 2" };
series.add("Series 1", categories, new double[] { 1.0, 2.0 });
series.add("Series 2", categories, new double[] { 3.0, 4.0 });
// Format chart background.
chart.getFormat().getFill().solid(Color.darkGray);
// Hide axis tick labels.
chart.getAxisX().getTickLabels().setPosition(AxisTickLabelPosition.NONE);
chart.getAxisY().getTickLabels().setPosition(AxisTickLabelPosition.NONE);
// Format chart title.
chart.getTitle().getFormat().getFill().solid(Color.yellow);
// Format axis title.
chart.getAxisX().getTitle().setShow(true);
chart.getAxisX().getTitle().getFormat().getFill().solid(Color.yellow);
// Format legend.
chart.getLegend().getFormat().getFill().solid(Color.yellow);
doc.save(getArtifactsDir() + "Charts.ChartFormat.docx");
Methods
getDashStyle()
public int getDashStyle()
Returns: int
getEndArrowLength()
public int getEndArrowLength()
Returns: int
getEndArrowType()
public int getEndArrowType()
Returns: int
getEndArrowWidth()
public int getEndArrowWidth()
Returns: int
getEndCap()
public int getEndCap()
Returns: int
getFill()
public Fill getFill()
Gets fill formatting for the parent chart element.
Examples:
Show how to set marker formatting.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.SCATTER, 432.0, 252.0);
Chart chart = shape.getChart();
// Delete default generated series.
chart.getSeries().clear();
ChartSeries series = chart.getSeries().add("AW Series 1", new double[] { 0.7, 1.8, 2.6, 3.9 },
new double[] { 2.7, 3.2, 0.8, 1.7 });
// Set marker formatting.
series.getMarker().setSize(40);
series.getMarker().setSymbol(MarkerSymbol.SQUARE);
ChartDataPointCollection dataPoints = series.getDataPoints();
dataPoints.get(0).getMarker().getFormat().getFill().presetTextured(PresetTexture.DENIM);
dataPoints.get(0).getMarker().getFormat().getStroke().setForeColor(Color.YELLOW);
dataPoints.get(0).getMarker().getFormat().getStroke().setBackColor(Color.RED);
dataPoints.get(1).getMarker().getFormat().getFill().presetTextured(PresetTexture.WATER_DROPLETS);
dataPoints.get(1).getMarker().getFormat().getStroke().setForeColor(Color.YELLOW);
dataPoints.get(1).getMarker().getFormat().getStroke().setVisible(false);
dataPoints.get(2).getMarker().getFormat().getFill().presetTextured(PresetTexture.GREEN_MARBLE);
dataPoints.get(2).getMarker().getFormat().getStroke().setForeColor(Color.YELLOW);
dataPoints.get(3).getMarker().getFormat().getFill().presetTextured(PresetTexture.OAK);
dataPoints.get(3).getMarker().getFormat().getStroke().setForeColor(Color.YELLOW);
dataPoints.get(3).getMarker().getFormat().getStroke().setTransparency(0.5);
doc.save(getArtifactsDir() + "Charts.MarkerFormatting.docx");
Returns: Fill - Fill formatting for the parent chart element.
getFillType()
public int getFillType()
Returns: int
getFillableBackColor()
public Color getFillableBackColor()
Returns: java.awt.Color
getFillableBackThemeColor()
public int getFillableBackThemeColor()
Returns: int
getFillableBackTintAndShade()
public double getFillableBackTintAndShade()
Returns: double
getFillableBaseForeColor()
public Color getFillableBaseForeColor()
Returns: java.awt.Color
getFillableForeColor()
public Color getFillableForeColor()
Returns: java.awt.Color
getFillableForeThemeColor()
public int getFillableForeThemeColor()
Returns: int
getFillableForeTintAndShade()
public double getFillableForeTintAndShade()
Returns: double
getFillableImageBytes()
public byte[] getFillableImageBytes()
Returns: byte[]
getFillableTransparency()
public double getFillableTransparency()
Returns: double
getFillableVisible()
public boolean getFillableVisible()
Returns: boolean
getFilledColor()
public Color getFilledColor()
Returns: java.awt.Color
getGradientAngle()
public double getGradientAngle()
Returns: double
getGradientStops()
public GradientStopCollection getGradientStops()
Returns: GradientStopCollection
getGradientStyle()
public int getGradientStyle()
Returns: int
getGradientVariant()
public int getGradientVariant()
Returns: int
getJoinStyle()
public int getJoinStyle()
Returns: int
getLineFillType()
public int getLineFillType()
Returns: int
getLineStyle()
public int getLineStyle()
Returns: int
getOldOn()
public boolean getOldOn()
Returns: boolean
getOldOpacity()
public double getOldOpacity()
Returns: double
getPatternType()
public int getPatternType()
Returns: int
getPresetTexture()
public int getPresetTexture()
Returns: int
getRotateWithObject()
public boolean getRotateWithObject()
Returns: boolean
getShapeType()
public int getShapeType()
Gets the shape type of the parent chart element.
Remarks:
Currently, the property can only be used for data labels.
Examples:
Shows how to set fill, stroke and callout formatting for chart data labels.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
Chart chart = shape.getChart();
// Delete default generated series.
chart.getSeries().clear();
// Add new series.
ChartSeries series = chart.getSeries().add("AW Series 1",
new String[] { "AW Category 1", "AW Category 2", "AW Category 3", "AW Category 4" },
new double[] { 100.0, 200.0, 300.0, 400.0 });
// Show data labels.
series.hasDataLabels(true);
series.getDataLabels().setShowValue(true);
// Format data labels as callouts.
ChartFormat format = series.getDataLabels().getFormat();
format.setShapeType(ChartShapeType.WEDGE_RECT_CALLOUT);
format.getStroke().setColor(Color.lightGray);
format.getFill().solid(Color.GREEN);
series.getDataLabels().getFont().setColor(Color.YELLOW);
// Change fill and stroke of an individual data label.
ChartFormat labelFormat = series.getDataLabels().get(0).getFormat();
labelFormat.getStroke().setColor(Color.BLUE);
labelFormat.getFill().solid(Color.BLUE);
doc.save(getArtifactsDir() + "Charts.FormatDataLables.docx");
Returns: int - The shape type of the parent chart element. The returned value is one of ChartShapeType constants.
getStartArrowLength()
public int getStartArrowLength()
Returns: int
getStartArrowType()
public int getStartArrowType()
Returns: int
getStartArrowWidth()
public int getStartArrowWidth()
Returns: int
getStroke()
public Stroke getStroke()
Gets line formatting for the parent chart element.
Examples:
Show how to set marker formatting.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.SCATTER, 432.0, 252.0);
Chart chart = shape.getChart();
// Delete default generated series.
chart.getSeries().clear();
ChartSeries series = chart.getSeries().add("AW Series 1", new double[] { 0.7, 1.8, 2.6, 3.9 },
new double[] { 2.7, 3.2, 0.8, 1.7 });
// Set marker formatting.
series.getMarker().setSize(40);
series.getMarker().setSymbol(MarkerSymbol.SQUARE);
ChartDataPointCollection dataPoints = series.getDataPoints();
dataPoints.get(0).getMarker().getFormat().getFill().presetTextured(PresetTexture.DENIM);
dataPoints.get(0).getMarker().getFormat().getStroke().setForeColor(Color.YELLOW);
dataPoints.get(0).getMarker().getFormat().getStroke().setBackColor(Color.RED);
dataPoints.get(1).getMarker().getFormat().getFill().presetTextured(PresetTexture.WATER_DROPLETS);
dataPoints.get(1).getMarker().getFormat().getStroke().setForeColor(Color.YELLOW);
dataPoints.get(1).getMarker().getFormat().getStroke().setVisible(false);
dataPoints.get(2).getMarker().getFormat().getFill().presetTextured(PresetTexture.GREEN_MARBLE);
dataPoints.get(2).getMarker().getFormat().getStroke().setForeColor(Color.YELLOW);
dataPoints.get(3).getMarker().getFormat().getFill().presetTextured(PresetTexture.OAK);
dataPoints.get(3).getMarker().getFormat().getStroke().setForeColor(Color.YELLOW);
dataPoints.get(3).getMarker().getFormat().getStroke().setTransparency(0.5);
doc.save(getArtifactsDir() + "Charts.MarkerFormatting.docx");
Returns: Stroke - Line formatting for the parent chart element.
getStrokeBackThemeColor()
public int getStrokeBackThemeColor()
Returns: int
getStrokeBackTintAndShade()
public double getStrokeBackTintAndShade()
Returns: double
getStrokeForeThemeColor()
public int getStrokeForeThemeColor()
Returns: int
getStrokeForeTintAndShade()
public double getStrokeForeTintAndShade()
Returns: double
getStrokeImageBytes()
public byte[] getStrokeImageBytes()
Returns: byte[]
getStrokeTransparency()
public double getStrokeTransparency()
Returns: double
getStrokeVisible()
public boolean getStrokeVisible()
Returns: boolean
getTextureAlignment()
public int getTextureAlignment()
Returns: int
getWeight()
public double getWeight()
Returns: double
isDefined()
public boolean isDefined()
Gets a flag indicating whether any format is defined.
Examples:
Shows how to reset the fill to the default value defined in the series.
Document doc = new Document(getMyDir() + "DataPoint format.docx");
Shape shape = (Shape)doc.getChild(NodeType.SHAPE, 0, true);
ChartSeries series = shape.getChart().getSeries().get(0);
ChartDataPoint dataPoint = series.getDataPoints().get(1);
Assert.assertTrue(dataPoint.getFormat().isDefined());
dataPoint.getFormat().setDefaultFill();
doc.save(getArtifactsDir() + "Charts.ResetDataPointFill.docx");
Returns: boolean - A flag indicating whether any format is defined.
oneColorGradient(int style, int variant, double degree)
public void oneColorGradient(int style, int variant, double degree)
Parameters:
Parameter | Type | Description |
---|---|---|
style | int | |
variant | int | |
degree | double |
patterned(int patternType)
public void patterned(int patternType)
Parameters:
Parameter | Type | Description |
---|---|---|
patternType | int |
presetTextured(int presetTexture)
public void presetTextured(int presetTexture)
Parameters:
Parameter | Type | Description |
---|---|---|
presetTexture | int |
setDashStyle(int value)
public void setDashStyle(int value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
setDefaultFill()
public void setDefaultFill()
Resets the fill of the chart element to have the default value.
Examples:
Shows how to reset the fill to the default value defined in the series.
Document doc = new Document(getMyDir() + "DataPoint format.docx");
Shape shape = (Shape)doc.getChild(NodeType.SHAPE, 0, true);
ChartSeries series = shape.getChart().getSeries().get(0);
ChartDataPoint dataPoint = series.getDataPoints().get(1);
Assert.assertTrue(dataPoint.getFormat().isDefined());
dataPoint.getFormat().setDefaultFill();
doc.save(getArtifactsDir() + "Charts.ResetDataPointFill.docx");
setEndArrowLength(int value)
public void setEndArrowLength(int value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
setEndArrowType(int value)
public void setEndArrowType(int value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
setEndArrowWidth(int value)
public void setEndArrowWidth(int value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
setEndCap(int value)
public void setEndCap(int value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
setFillableBackColor(Color value)
public void setFillableBackColor(Color value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.awt.Color |
setFillableBackThemeColor(int value)
public void setFillableBackThemeColor(int value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
setFillableBackTintAndShade(double value)
public void setFillableBackTintAndShade(double value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | double |
setFillableForeColor(Color value)
public void setFillableForeColor(Color value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.awt.Color |
setFillableForeThemeColor(int value)
public void setFillableForeThemeColor(int value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
setFillableForeTintAndShade(double value)
public void setFillableForeTintAndShade(double value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | double |
setFillableTransparency(double value)
public void setFillableTransparency(double value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | double |
setFillableVisible(boolean value)
public void setFillableVisible(boolean value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | boolean |
setFilledColor(Color value)
public void setFilledColor(Color value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.awt.Color |
setGradientAngle(double value)
public void setGradientAngle(double value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | double |
setImage(byte[] imageBytes)
public void setImage(byte[] imageBytes)
Parameters:
Parameter | Type | Description |
---|---|---|
imageBytes | byte[] |
setJoinStyle(int value)
public void setJoinStyle(int value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
setLineFillType(int value)
public void setLineFillType(int value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
setLineStyle(int value)
public void setLineStyle(int value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
setOldOn(boolean value)
public void setOldOn(boolean value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | boolean |
setOldOpacity(double value)
public void setOldOpacity(double value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | double |
setRotateWithObject(boolean value)
public void setRotateWithObject(boolean value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | boolean |
setShapeType(int value)
public void setShapeType(int value)
Sets the shape type of the parent chart element.
Remarks:
Currently, the property can only be used for data labels.
Examples:
Shows how to set fill, stroke and callout formatting for chart data labels.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
Chart chart = shape.getChart();
// Delete default generated series.
chart.getSeries().clear();
// Add new series.
ChartSeries series = chart.getSeries().add("AW Series 1",
new String[] { "AW Category 1", "AW Category 2", "AW Category 3", "AW Category 4" },
new double[] { 100.0, 200.0, 300.0, 400.0 });
// Show data labels.
series.hasDataLabels(true);
series.getDataLabels().setShowValue(true);
// Format data labels as callouts.
ChartFormat format = series.getDataLabels().getFormat();
format.setShapeType(ChartShapeType.WEDGE_RECT_CALLOUT);
format.getStroke().setColor(Color.lightGray);
format.getFill().solid(Color.GREEN);
series.getDataLabels().getFont().setColor(Color.YELLOW);
// Change fill and stroke of an individual data label.
ChartFormat labelFormat = series.getDataLabels().get(0).getFormat();
labelFormat.getStroke().setColor(Color.BLUE);
labelFormat.getFill().solid(Color.BLUE);
doc.save(getArtifactsDir() + "Charts.FormatDataLables.docx");
Parameters:
Parameter | Type | Description |
---|---|---|
value | int | The shape type of the parent chart element. The value must be one of ChartShapeType constants. |
setStartArrowLength(int value)
public void setStartArrowLength(int value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
setStartArrowType(int value)
public void setStartArrowType(int value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
setStartArrowWidth(int value)
public void setStartArrowWidth(int value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
setStrokeBackThemeColor(int value)
public void setStrokeBackThemeColor(int value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
setStrokeBackTintAndShade(double value)
public void setStrokeBackTintAndShade(double value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | double |
setStrokeForeThemeColor(int value)
public void setStrokeForeThemeColor(int value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
setStrokeForeTintAndShade(double value)
public void setStrokeForeTintAndShade(double value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | double |
setStrokeTransparency(double value)
public void setStrokeTransparency(double value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | double |
setStrokeVisible(boolean value)
public void setStrokeVisible(boolean value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | boolean |
setTextureAlignment(int value)
public void setTextureAlignment(int value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
setWeight(double value)
public void setWeight(double value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | double |
solid()
public void solid()
twoColorGradient(int style, int variant)
public void twoColorGradient(int style, int variant)
Parameters:
Parameter | Type | Description |
---|---|---|
style | int | |
variant | int |