Skip to content

Plot.Add.Pie() adds multiple pie charts (and multiple legends) #3445

@swharden

Description

@swharden

This issue was emailed to me from Jeff Haley

The legend is duplicated after adding a pie chart: I looked at the PlottableList and noticed that the software had actually added 2 pie charts instead of just one. They were both referencing the same object. I have pasted the code containing the error below. Only the function called with the PieSlice list needs to add the pie chart to the plottable list as it is always called by the function with the double valued array below it. This may affect some of the other overridden functions. I hope this helps. In my project I have used RemoveAt on the PlottableList to remove the extra pie chart object. I think this is an excellent library, very fast and extremely useful. I hope I have helped in some small way.

The error is in this portion of the code:

public Pie Pie(IList<PieSlice> slices)
{
Pie pie = new(slices);
Plot.PlottableList.Add(pie);
return pie;
}
public Pie Pie(IEnumerable<double> values)
{
List<PieSlice> slices = new();
foreach (double value in values)
{
PieSlice slice = new()
{
Value = value,
FillColor = Palette.GetColor(slices.Count),
};
slices.Add(slice);
}
var pie = Pie(slices);
Plot.PlottableList.Add(pie);
return pie;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good First IssueThis issue has limited complexity and may be a good start for new contributorsHelp WantedScott won't do this soon, but PRs from the community are welcome!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions