Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

336
Views
Resize Chart Independently From Legend in ChartJS for Canvas Download

Some of the charts created and downloaded by my application have the potential to have very large legends. When this is the case, the idea is to create (ideally via ChartJs - as is the case with the associated chart) and download a dedicated canvas/image showing the full legend for the chart.

So far, I have been able to "hide" the chart by setting the scales to display: false e.g.

options: {
  scales: {
    x: {
      display: false
    },
    y: {
      display: false
    }

This successfully prevents the chart from showing, but the canvas still seems to allocate half the real-estate for the chart e.g.

enter image description here

Is there any way I can make the space for the chart smaller (or even disable it from showing at all!) allowing more space for the legend?

Playground here: https://jsfiddle.net/ShallDev2018/7bdnjsw9/16/

NOTE: HtmlLegend is not an option here as the sole purpose of this canvas is for downloads.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After some more tinkering, I have found the solution to the problem.

As it happens, ChartJs sets a default max-width for the legend (although it doesn't specify this in the documentation). By setting legend max width to a high value, the legend can assume the whole canvas e.g.

legend: {
  position: 'left',
  align: 'start',
  fullSize: false,
  labels: {
    font: {
      size: 12
    },
    padding: 10
  },
  maxWidth: 9999
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!