mariusmuntean / ChartJs.Blazor

Brings Chart.js charts to Blazor
https://www.iheartblazor.com/
MIT License
676 stars 151 forks source link

Layout Configuration #156

Closed ipax77 closed 6 months ago

ipax77 commented 3 years ago

Adding Layout Configuration to BaseConfigOptions.

Which charts does this feature request apply to?

all charts

Describe the solution you'd like

                Options = new PieOptions
                {
                    Layout = new Layout() {
                        Padding = new Padding()
                        {
                            top = 50,
                            left = 50,
                            right = 50,
                            bottom = 50
                        }
                    },
                    Responsive = true,
                    ...
                }

JavaScript equivalent

            options: {
                layout: {
                    padding: {
                        left: 50,
                        right: 50,
                        top: 50,
                        bottom: 50
                    }
                },
                responsive: true,
                ...
           }

Describe alternatives you've considered

Setting global chart layout with JavaScript in Chart.defaults.global.layout

Additional context

image

Joelius300 commented 3 years ago

Thank you for the issue. We should definitely add that.

I'll take a look at your PR when I get time. Since I'm in the final phase of releasing 2.0, this might be released in 2.1 or so.

For now the workaround should be fine but if you want a C#-only solution, you can subclass your PieOptions and add a property named Layout. You can make it of type object and then assign an annonymous object or go the typed way (which results in more code obviously). Both will be serialized and should yield the correct result (untested).

akirayamamoto commented 8 months ago

I will create a PR to cherry-pick this commit. What do you think? cc @mariusmuntean