Skip to content

How to create a doughnut chart in Scott Plot 5 #3438

@Prototipo-Erick-Santander

Description

Question: I Would like to know how can I create a doughnut chart in Scott Plot 5, I know that I can make a pie chart and on V4.1 there used to be a .DonutSize property, which is no longer available.

ScottPlot Version: 5

Code Sample:

public void Create_ScottPlot_Doughnut(string path)
    {
        double[] values = { 44.2, 51.9, .09, 1.1, .8, 1.1 };
        string[] labels = { "External", "Sold", "Personel", "Others", "Depreciation", "Tax" };
        var palette = new ScottPlot.Palettes.Category20();
        
        // Define the slices for the doughnut chart
        var slices = new List<PieSlice>();
        for (var i = 0; i < values.Length; i++)
        {
            var slice = new PieSlice
            {
                Value = values[i], 
                Label = values[i].ToString("N2"),
                LabelStyle = new Label { IsVisible = true },
                FillColor = palette.Colors[i],
            };
            
            slices.Add(slice);
        }

        // Add the doughnut chart to the plot
        Plot myPlot = new();
        var pie = myPlot.Add.Pie(slices);
        
        //pie.ExplodeFraction = 0.05; // Set the donut size to create a hollow center
        pie.ShowSliceLabels = true;
        pie.SliceLabelDistance = 1.3;
        pie.LineStyle.Width = 0;

        myPlot.HideGrid();
        myPlot.Layout.Frameless();
        myPlot.Legend.IsVisible = true;
        myPlot.Legend.Location = Alignment.LowerCenter;
        
        myPlot.SavePng(path, 1000, 650);
        Console.ReadKey();
    }

This is something like what I would like to do:
image
Is it also possible to make the labels never be on top of one another?

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