Skip to content

Legend Items seem to ignore the marker style setting #5005

@aespitia

Description

@aespitia

Issue: It looks like looping through legend items to update the marker style from the default to another markerstyle doesn't work. From looking at the code it also looks like some plot types set a default marker to a filled circle, but the current implementation ignores it.

ScottPlot Version: 5.0.55

Code Sample:

ScottPlot.Plot myPlot = new();

List<PieSlice> slices =
[
	new PieSlice() { Value = 5, FillColor = Colors.Red, Label = "Red", LegendText = "R" },
	new PieSlice() { Value = 2, FillColor = Colors.Orange, Label = "Orange" },
	new PieSlice() { Value = 8, FillColor = Colors.Gold, Label = "Yellow" },
	new PieSlice() { Value = 4, FillColor = Colors.Green, Label = "Green", LegendText = "G" },
	new PieSlice() { Value = 8, FillColor = Colors.Blue, Label = "Blue", LegendText = "B" },
];

var pie = myPlot.Add.Pie(slices);
pie.ExplodeFraction = .1;
pie.SliceLabelDistance = 1.4;

var legitems = myPlot.Legend.GetItems();

foreach (var item in legitems)
{
	item.LabelText = item.LabelText + "-modified";
	item.MarkerStyle.Shape = MarkerShape.FilledCircle;
	item.MarkerShape = MarkerShape.FilledCircle;
	item.MarkerColor = item.FillColor;
	item.MarkerSize = 20;

	/*
	myPlot.Legend.ManualItems.Add(new LegendItem()
	{
		LabelText = item.LabelText,
		LabelFontName = item.LabelFontName,
		LabelFontSize = item.LabelFontSize,
		LabelFontColor = item.LabelFontColor,
		MarkerShape = MarkerShape.FilledCircle,
		MarkerColor = item.LineColor,
		MarkerSize = 10
	});
	*/
}

myPlot.ShowLegend();

myPlot.Axes.Frameless();
myPlot.HideGrid();

var bitmap = myPlot.GetImageBytes(400, 300);

Util.Image(bitmap).Dump();

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