com.aspose.words

Class ChartLegend

  • java.lang.Object
    • com.aspose.words.ChartLegend
  • All Implemented Interfaces:
    java.lang.Cloneable
    public class ChartLegend 
    extends java.lang.Object

Represents chart legend properties.

Example:

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");

Constructor Summary
ChartLegend()
Deprecated. Initializes a new instance of the ChartLegend class.
 
Property Getters/Setters Summary
ChartLegendEntryCollectiongetLegendEntries()
Returns a collection of legend entries for all series and trendlines of the parent chart.
booleangetOverlay()
void
setOverlay(booleanvalue)
           Determines whether other chart elements shall be allowed to overlap legend. Default value is false.
intgetPosition()
void
setPosition(intvalue)
           Specifies the position of the legend on a chart. Default value is LegendPosition.RIGHT. The value of the property is LegendPosition integer constant.
 

    • Constructor Detail

      • ChartLegend

        @Deprecated
        public ChartLegend()
        Deprecated. Initializes a new instance of the ChartLegend class.
    • Property Getters/Setters Detail

      • getLegendEntries

        public ChartLegendEntryCollection getLegendEntries()
        
        Returns a collection of legend entries for all series and trendlines of the parent chart.
      • getOverlay/setOverlay

        public boolean getOverlay() / public void setOverlay(boolean value)
        
        Determines whether other chart elements shall be allowed to overlap legend. Default value is false.

        Example:

        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");
      • getPosition/setPosition

        public int getPosition() / public void setPosition(int value)
        
        Specifies the position of the legend on a chart. Default value is LegendPosition.RIGHT. The value of the property is LegendPosition integer constant.

        Example:

        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");