Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

341
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda