public class ChartLegend
extends java.lang.Object
implements java.lang.Cloneable
To learn more, visit the Working with Charts documentation article.
Examples:
Shows how to edit the appearance of a chart's legend.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.LINE, 450.0, 300.0);
Chart chart = shape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Move the chart's legend to the top right corner.
ChartLegend legend = chart.getLegend();
legend.setPosition(LegendPosition.TOP_RIGHT);
// Give other chart elements, such as the graph, more room by allowing them to overlap the legend.
legend.setOverlay(true);
doc.save(getArtifactsDir() + "Charts.ChartLegend.docx");
| Modifier and Type | Method and Description |
|---|---|
Font |
getFont()
Provides access to the default font formatting of legend entries.
|
ChartFormat |
getFormat()
Provides access to fill and line formatting of the legend.
|
ChartLegendEntryCollection |
getLegendEntries()
Returns a collection of legend entries for all series and trendlines of the parent chart.
|
boolean |
getOverlay()
Determines whether other chart elements shall be allowed to overlap legend.
|
int |
getPosition()
Specifies the position of the legend on a chart.
|
int |
getShapeType() |
boolean |
isFillSupported() |
boolean |
isFormatDefined() |
void |
materializeSpPr() |
protected java.lang.Object |
memberwiseClone() |
void |
setOverlay(boolean value)
Determines whether other chart elements shall be allowed to overlap legend.
|
void |
setPosition(int value)
Specifies the position of the legend on a chart.
|
void |
setShapeType(int value) |
public ChartLegendEntryCollection getLegendEntries()
Examples:
Shows how to work with a legend entry for chart series.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
Chart chart = shape.getChart();
ChartSeriesCollection series = chart.getSeries();
series.clear();
String[] categories = new String[] { "AW Category 1", "AW Category 2" };
ChartSeries series1 = series.add("Series 1", categories, new double[] { 1.0, 2.0 });
series.add("Series 2", categories, new double[] { 3.0, 4.0 });
series.add("Series 3", categories, new double[] { 5.0, 6.0 });
series.add("Series 4", categories, new double[] { 0.0, 0.0 });
ChartLegendEntryCollection legendEntries = chart.getLegend().getLegendEntries();
legendEntries.get(3).isHidden(true);
doc.save(getArtifactsDir() + "Charts.LegendEntries.docx");
public int getPosition()
Remarks:
The default value is LegendPosition.RIGHT for pre-Word 2016 charts and LegendPosition.TOP for Word 2016 charts.
Examples:
Shows how to edit the appearance of a chart's legend.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.LINE, 450.0, 300.0);
Chart chart = shape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Move the chart's legend to the top right corner.
ChartLegend legend = chart.getLegend();
legend.setPosition(LegendPosition.TOP_RIGHT);
// Give other chart elements, such as the graph, more room by allowing them to overlap the legend.
legend.setOverlay(true);
doc.save(getArtifactsDir() + "Charts.ChartLegend.docx");
int value. The returned value is one of LegendPosition constants.public void setPosition(int value)
Remarks:
The default value is LegendPosition.RIGHT for pre-Word 2016 charts and LegendPosition.TOP for Word 2016 charts.
Examples:
Shows how to edit the appearance of a chart's legend.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.LINE, 450.0, 300.0);
Chart chart = shape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Move the chart's legend to the top right corner.
ChartLegend legend = chart.getLegend();
legend.setPosition(LegendPosition.TOP_RIGHT);
// Give other chart elements, such as the graph, more room by allowing them to overlap the legend.
legend.setOverlay(true);
doc.save(getArtifactsDir() + "Charts.ChartLegend.docx");
value - The corresponding int value. The value must be one of LegendPosition constants.public Font getFont()
ChartLegendEntry.getFont() property.
Examples:
Shows how to work with a legend font.
Document doc = new Document(getMyDir() + "Reporting engine template - Chart series (Java).docx");
Chart chart = ((Shape)doc.getChild(NodeType.SHAPE, 0, true)).getChart();
ChartLegend chartLegend = chart.getLegend();
// Set default font size all legend entries.
chartLegend.getFont().setSize(14.0);
// Change font for specific legend entry.
chartLegend.getLegendEntries().get(1).getFont().setItalic(true);
chartLegend.getLegendEntries().get(1).getFont().setSize(12.0);
// Get legend entry for chart series.
ChartLegendEntry legendEntry = chart.getSeries().get(0).getLegendEntry();
doc.save(getArtifactsDir() + "Charts.LegendFont.docx");
Font value.public ChartFormat getFormat()
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");
ChartFormat value.public boolean getOverlay()
false.
Examples:
Shows how to edit the appearance of a chart's legend.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.LINE, 450.0, 300.0);
Chart chart = shape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Move the chart's legend to the top right corner.
ChartLegend legend = chart.getLegend();
legend.setPosition(LegendPosition.TOP_RIGHT);
// Give other chart elements, such as the graph, more room by allowing them to overlap the legend.
legend.setOverlay(true);
doc.save(getArtifactsDir() + "Charts.ChartLegend.docx");
boolean value.public void setOverlay(boolean value)
false.
Examples:
Shows how to edit the appearance of a chart's legend.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.LINE, 450.0, 300.0);
Chart chart = shape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Move the chart's legend to the top right corner.
ChartLegend legend = chart.getLegend();
legend.setPosition(LegendPosition.TOP_RIGHT);
// Give other chart elements, such as the graph, more room by allowing them to overlap the legend.
legend.setOverlay(true);
doc.save(getArtifactsDir() + "Charts.ChartLegend.docx");
value - The corresponding boolean value.public void materializeSpPr()
public boolean isFillSupported()
public int getShapeType()
public void setShapeType(int value)
public boolean isFormatDefined()
protected java.lang.Object memberwiseClone()