Main Content

getLegend

Class: matlab.graphics.chartcontainer.mixin.Legend
Namespace: matlab.graphics.chartcontainer.mixin

Get legend object for legend mixin subclass

Since R2019b

Syntax

lgd = getLegend(obj)

Description

lgd = getLegend(obj) returns the legend for a chart object that inherits from the matlab.graphics.chartcontainer.mixin.Legend class.

Input Arguments

expand all

Object of the class that inherits from the matlab.graphics.chartcontainer.mixin.Legend class.

Output Arguments

expand all

Legend object for the chart.

Attributes

Protectedtrue

To learn about attributes of methods, see Method Attributes.

Examples

expand all

Create a setup method in your class definition file. Within that method, call getLegend to get the legend object lgd. Then change the text color, box edge color, and box line width.

classdef ConfigLegendChart < matlab.graphics.chartcontainer.ChartContainer & ...
        matlab.graphics.chartcontainer.mixin.Legend
    
    properties
        % ...
    end
    
    methods(Access = protected)
        function setup(obj)
            % Make legend visible
            obj.LegendVisible = 'on';
            
            % Get legend and set text color, edge color, and line width
            lgd = getLegend(obj);
            lgd.TextColor = [.3 .3 .3];
            lgd.EdgeColor = [.8 .8 .8];
            lgd.LineWidth = .7;
        end
        function update(obj)
            % ...
        end
    end
end

Version History

Introduced in R2019b