microcharts-dotnet / Microcharts

Create cross-platform (Xamarin, Windows, ...) simple charts.
MIT License
2.03k stars 360 forks source link

[Question] How Can I add Text In the Center Of the Dount Chart? #341

Open abdulrahmannady opened 1 year ago

abdulrahmannady commented 1 year ago

Is there a way to allow adding Text inside the chart beside the ones on the right side

chart here is the chart I have

and the example I'm using please note I'm using QuestPDF with Microcharts

var entries = new[]
{
    new ChartEntry(7)
    {
        Label = "Available Limit",
        ValueLabel = "7000",
        Color = SKColor.Parse("#1976D2"), // Blue
        ValueLabelColor = SKColor.Parse("#1976D2")
    },
    new ChartEntry(2)
    {
        Label = "Closing Balance",
        ValueLabel = "2000",
        Color = SKColor.Parse("#689F38"), // Light Green
        ValueLabelColor = SKColor.Parse("#689F38")
    },
    new ChartEntry(1)
    {
        Label = "Installments Deferred",
        ValueLabel = "1000",
        Color = SKColor.Parse("#FFC107"), // Yellow
        ValueLabelColor = SKColor.Parse("#FFC107")
    },
    new ChartEntry(3)
    {
        Label = "Overdue",
        ValueLabel = "3000",
        Color = SKColor.Parse("#F44336"), // Red
        ValueLabelColor = SKColor.Parse("#F44336")
    }
};

Document.Create(container =>
{
    container.Page(page =>
    {
        page
        .Content()
        .Column(column =>
        {
            var titleStyle = TextStyle
                .Default
                .FontSize(20)
                .SemiBold()
                .FontColor(Colors.Blue.Medium);

            column
                .Item()
                .Height(450)
                .Width(560)
                .Border(1)
                .Canvas((canvas, size) =>
                {
                    var chart = new DonutChart
                    {
                        Entries = entries,
                        AnimationProgress = 0,
                        Margin = 20,
                        LabelTextSize = 15,
                        IsAnimated = false,
                        AnimationDuration = default,
                        HoleRadius = 0.6f,
                        LabelMode = LabelMode.RightOnly,
                        GraphPosition = GraphPosition.AutoFill
                    };

                    chart.Draw(canvas, (int)size.Width, (int)size.Height);
                });
        });
    });
}).ShowInPreviewer();