Skip to content

Legend: how to toggle visibility for each plottable #1482

@CD-SailingPerf

Description

@CD-SailingPerf

Should be fairly simple. I pulled the source code and did a quick test.
In ScottPlot.Plottable.ScatterPlot:

public bool ShowInLegend { get; set; } = true;

       public LegendItem[] GetLegendItems()
        {

if (!ShowInLegend) return null;

            var singleLegendItem = new LegendItem()
            {
                label = Label,
                color = Color,
                lineStyle = LineStyle,
                lineWidth = LineWidth,
                markerShape = MarkerShape,
                markerSize = MarkerSize
            };
            return new LegendItem[] { singleLegendItem };
        }

That seemed to work well, I can now choose if I want a plot to be displayed in the legend or not. Simply adding

 public bool ShowInLegend { get; set; } = true;

and

            if (!ShowInLegend) return null;

to all Plottables which don't return null on GetLegendItems should work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions