ChartLegendEntry
Inheritance: java.lang.Object
All Implemented Interfaces: java.lang.Cloneable
public class ChartLegendEntry implements Cloneable
Represents a chart legend entry.
To learn more, visit the Working with Charts documentation article.
Remarks:
A legend entry corresponds to a specific chart series or trendline.
The text of the entry is the name of the series or trendline. The text cannot be changed.
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);
doc.save(getArtifactsDir() + "Charts.LegendFont.docx");
Methods
Method | Description |
---|---|
fetchSpecialDefaultRunPropertyValue(int key) | |
generateItemText() | |
getFont() | Provides access to the font formatting of this legend entry. |
getRelativePropertyValue(int key, Object value) | |
isHidden() | Gets a value indicating whether this entry is hidden in the chart legend. |
isHidden(boolean value) | Sets a value indicating whether this entry is hidden in the chart legend. |
fetchSpecialDefaultRunPropertyValue(int key)
public Object fetchSpecialDefaultRunPropertyValue(int key)
Parameters:
Parameter | Type | Description |
---|---|---|
key | int |
Returns: java.lang.Object
generateItemText()
public String generateItemText()
Returns: java.lang.String
getFont()
public Font getFont()
Provides access to the font formatting of this legend entry.
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);
doc.save(getArtifactsDir() + "Charts.LegendFont.docx");
Returns: Font - The corresponding Font value.
getRelativePropertyValue(int key, Object value)
public Object getRelativePropertyValue(int key, Object value)
Parameters:
Parameter | Type | Description |
---|---|---|
key | int | |
value | java.lang.Object |
Returns: java.lang.Object
isHidden()
public boolean isHidden()
Gets a value indicating whether this entry is hidden in the chart legend. The default value is false.
Remarks:
When a chart legend entry is hidden, it does not affect the corresponding chart series or trendline that is still displayed on the chart.
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");
Returns: boolean - A value indicating whether this entry is hidden in the chart legend.
isHidden(boolean value)
public void isHidden(boolean value)
Sets a value indicating whether this entry is hidden in the chart legend. The default value is false.
Remarks:
When a chart legend entry is hidden, it does not affect the corresponding chart series or trendline that is still displayed on the chart.
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");
Parameters:
Parameter | Type | Description |
---|---|---|
value | boolean | A value indicating whether this entry is hidden in the chart legend. |