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 Overflow Handling #6545

Closed
RobTables opened this issue Sep 30, 2019 · 5 comments
Closed

Legend Overflow Handling #6545

RobTables opened this issue Sep 30, 2019 · 5 comments

Comments

@RobTables
Copy link

I have been using Chart.js 2 quite a lot recently and there is one feature I have seen suggested but has been overlooked. Adding overflow handling for the legend would help me out immensely. Currently I have some datasets that could have anywhere from 10 - 50 keys in the legend. I have seen solutions like those found here but would like to avoid having to separate my legend from the chart. Adding the ability to set the dimensions of the legend within the canvas object as well as what do when our labels go beyond those dimensions would be very beneficial to my projects.

			legend:{
				labels:{
					fontStyle: "bold",
				},
				display: true,
				position: 'right',
                                width: 100, //suggested
                                height: 200, //suggested
                                overflowX: hide, //suggested
                                overflowY: scroll, //suggested
			},
@benmccann
Copy link
Contributor

You can make a custom html legend: https://www.chartjs.org/docs/latest/configuration/legend.html#html-legends

@systemallica
Copy link

Although we can create a custom legend, having the possibility of using the provided one and modify its height, width and overflow behaviour would be certainly easier for the user.

I would like to see this feature implemented.

@peteruithoven
Copy link

The legend is drawn in the canvas (unless you add a custom html legend), they would have to add custom scrolling behaivior for this, which will never be as good as the browser's build in scrolling behaivior. This simply doesn't seem feasible?

If you want scrolling behavior, using the browser's build in functionality seems like the way to go, which means using a html legend.

@riancintiyo
Copy link

riancintiyo commented Apr 28, 2022

You can update and move the legend position, change the font size, or even deactivate the legend dynamically by using onResize function (https://www.chartjs.org/docs/latest/configuration/responsive.html), this function passed two arguments which are Context and size.

So, we can use onResize function to mutating the option configuration (the documentation for this : (https://www.chartjs.org/docs/latest/developers/updates.html) . In that documentation example shows that you can use this function to mutating the option configuration :

function updateConfigByMutating(chart) {
    chart.options.plugins.title.text = 'new title';
    chart.update();
}

From here, we can utilize the query inside function updateConfigByMutating(chart) place it inside onResize method and set whatever screen size condition.

@dangreen
Copy link
Collaborator

dangreen commented Nov 7, 2022

Hi guys. If you want to customize the legend visually, please use an HTML legend. Due to Chart.js using canvas, we can't implement every requested feature cause this will bloat the code.

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

No branches or pull requests

6 participants