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

Legend placement goes haywire when any of the aspect ratio classes are used #28

Closed
ghost opened this issue Oct 10, 2016 · 6 comments
Closed

Comments

@ghost
Copy link

ghost commented Oct 10, 2016

I am using the "ct-major-second" class for making my chart responsive and auto resizing the bars and stuff.... but any of these classes set the css "top" property to "0" hence making the legend overlap. This can be fixed using custom css, but it isnt recommended as it wont keep the chart and the legend dynamic (i have many pages that use these charts, few having 2 bars, few 5, few 10, etc etc) and i wont be able to handle the height of the legend in all cases if i keep it static.

Is there any way in which i could place the legend outside the entire chart container

as it would be very easy to handle such a situation in that case.

If not how do you suggest i could handle this...?

@devzing
Copy link

devzing commented Nov 1, 2016

Affecting me as well. Using ct-major-tenth

@tarekis
Copy link
Contributor

tarekis commented Nov 7, 2016

Well, chartist-plugin-legend places the ul element inside of the chart container, either before or after the svg chart, depending on your options.

If you want the ul to be placed, this has to be done with JS, probably the best approach ist to fork and implement a position option for flexibilty:

chart.on('created', function (data) {
    // Append the legend element to the DOM
    switch (options.position) {
        case 'top':
            chart.container.insertBefore(legendElement, chart.container.childNodes[0]);
            break;

        case 'bottom':
            chart.container.insertBefore(legendElement, null);
            break;

        case 'outertop':
            // Some logic to place the chart outside of the chart container
            break;
        }
});

How good that is and if that should be PR'd into the master sometimes, i can't say really; you might run into some unexpected styling problems because the legend is now somewhere outside the container, depending on your implementation.

@SpaceK33z
Copy link
Contributor

We could also allow the position option to take a DOM element. If a DOM element is given it attaches to that element instead of inside the chart. A PR is welcome for this, don't have the time myself atm.

@tarekis
Copy link
Contributor

tarekis commented Nov 7, 2016

That sounds sweet too, might look into it sometime soon.

SpaceK33z pushed a commit that referenced this issue Nov 14, 2016
Minified existing and added another example for the demo page
@tarekis
Copy link
Contributor

tarekis commented Nov 14, 2016

Works as of 0.6.0. You can now enter any HTMLElement into the position option.

@tarekis
Copy link
Contributor

tarekis commented Sep 14, 2017

I'm closing this as this should be resolved as of 0.6.0. If this issue remains, feel free to reopen it.

@tarekis tarekis closed this as completed Sep 14, 2017
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

3 participants