Pie: respect LineStyle, fix automatic axis limits, and demonstrate percent labels#4278
Merged
swharden merged 8 commits intoScottPlot:mainfrom Oct 9, 2024
LeaFrock:pie_percentage
Merged
Pie: respect LineStyle, fix automatic axis limits, and demonstrate percent labels#4278swharden merged 8 commits intoScottPlot:mainfrom LeaFrock:pie_percentage
LineStyle, fix automatic axis limits, and demonstrate percent labels#4278swharden merged 8 commits intoScottPlot:mainfrom
LeaFrock:pie_percentage
Conversation
aespitia
reviewed
Sep 20, 2024
Contributor
|
sorry, i was talking about this part: slicePercentFormat.StartsWith('P') // Just follow the code quality rule CA1865
#else
slicePercentFormat.StartsWith("P", StringComparison.Ordinal)in common usage, lowercase "p" actually works too. double number = .2468013;
Console.WriteLine(number.ToString("p", CultureInfo.InvariantCulture));
// Displays 24.68 %
Console.WriteLine(number.ToString("p", CultureInfo.CreateSpecificCulture("hr-HR")));
// Displays 24,68%
Console.WriteLine(number.ToString("p1", CultureInfo.InvariantCulture));
// Displays 24.7 % |
Contributor
Author
|
Well, the document doesn't mention the lower case. But after I check the source codes of |
Member
|
I believe this functionality is possible with the existing library and a code change is not required. I'll adapt this PR to add a cookbook recipe that demonstrates this 👍 // create a pie chart
double[] values = [6, 8, 10];
var pie = myPlot.Add.Pie(values);
pie.ExplodeFraction = .1;
pie.ShowSliceLabels = true;
pie.SliceLabelDistance = 0.5;
// determine percentages for each slice
double total = pie.Slices.Select(x => x.Value).Sum();
double[] percentages = pie.Slices.Select(x => x.Value / total * 100).ToArray();
// set each slice label to its percentage
for (int i = 0; i < pie.Slices.Count; i++)
{
pie.Slices[i].Label = $"{percentages[i]:0.0}%";
pie.Slices[i].LabelFontSize = 20;
pie.Slices[i].LabelBold = true;
pie.Slices[i].LabelFontColor = Colors.Black.WithAlpha(.5);
}
// hide unnecessary plot components
myPlot.Axes.Frameless();
myPlot.HideGrid();
myPlot.HideLegend(); |
LineStyle, fix automatic axis limits, and demonstrate percent labels
Contributor
Author
|
@swharden The problem is that sometimes we want two labels: one is inside(as a percent) and the other is outside(as a tag or other information). It's the original feature request of this PR. The current |
swharden
added a commit
to johndoh/ScottPlot
that referenced
this pull request
Oct 10, 2024
re-implementation of ScottPlot#4305 after ScottPlot#4278 and ScottPlot#4280 merge conflicts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Bring the feature of Pie plot which ScottPlot 4 owns to 5.