Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
abdulrahmannady opened this issue Oct 6, 2023 · 0 comments
Open
Labels

Comments

@abdulrahmannady
Copy link

abdulrahmannady commented Oct 6, 2023

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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant