java.lang.Object
com.aspose.words.ChartFormat
public class ChartFormat
- extends java.lang.Object
Represents the formatting of a chart element.
To learn more, visit the Working with Charts documentation article.
Example:
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");
|
Property Getters/Setters Summary |
Fill | getFill() | |
|
Gets fill formatting for the parent chart element.
|
boolean | isDefined() | |
|
Gets a flag indicating whether any format is defined.
|
int | getShapeType() | |
void | setShapeType(int value) | |
|
Gets or sets the shape type of the parent chart element.
The value of the property is ChartShapeType integer constant. |
Stroke | getStroke() | |
|
Gets line formatting for the parent chart element.
|
|
Method Summary |
void | setDefaultFill() | |
|
Resets the fill of the chart element to have the default value.
|
|
Property Getters/Setters Detail |
getFill | |
public Fill getFill()
|
-
Gets fill formatting for the parent chart element.
Example:
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");
isDefined | |
public boolean isDefined()
|
-
Gets a flag indicating whether any format is defined.
Example:
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");
getShapeType/setShapeType | |
public int getShapeType() / public void setShapeType(int value)
|
-
Gets or sets the shape type of the parent chart element.
The value of the property is ChartShapeType integer constant.
Currently, the property can only be used for data labels.
Example:
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");
getStroke | |
public Stroke getStroke()
|
-
Gets line formatting for the parent chart element.
Example:
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");
setDefaultFill | |
public void setDefaultFill() |
-
Resets the fill of the chart element to have the default value.
Example:
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");
See Also:
Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
Aspose.Words Support Forum - our preferred method of support.