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

Changing horizontal width of line chart / aspect ration #5

Open
bankian opened this issue Mar 31, 2021 · 1 comment
Open

Changing horizontal width of line chart / aspect ration #5

bankian opened this issue Mar 31, 2021 · 1 comment

Comments

@bankian
Copy link

bankian commented Mar 31, 2021

Thanks for this project - really useful!

I'd like to have a line chart that's much wider than it is high. I can easily alter the height of the chart by setting height in the ".main" class, but if I try to alter width it just changes the container and not the chart itself, so the chart is limited to having a square aspect ratio.

I was hoping that with SVG it would be easy to make the chart any aspect ratio - am I missing something?

Ian

@helloserve
Copy link

helloserve commented Aug 13, 2021

I added two new parameters to the LineChart component:

        [Parameter]
        public int BoundHeight { get; set; }

        [Parameter]
        public int BoundWidth { get; set; }

Then I use these to set the local variables boundHeight and boundWidth in the BuildRenderTree method, and I also changed the viewbox values to use those variables instead:

SVG svg = new SVG() { { "width", "100%" }, { "height", "100%" }, { "viewBox", $"0 0 {boundWidth} {boundHeight}" } };

This allowed me to set the size and aspect ratio of the graph.

Also, it's better to remove the with and height properties from the SVG code. Doing so lets the SVG become responsive, albeit it retains the aspect ratio from the bound values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants