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

107
Views
Chart js: bar width

I want to display data in chart js (version 3.7.1) with horizontal bar chart. Data are loading from backend. My problem is with widht of bar. When I have only a few records, bars are very thick.1 When I have a lot of records (for example 1000) bars are very narrow and are missing label.2 How can you see in images. I would like have still the same widht for bars and if is a lot of records enable scroll.

There is my code:

  createConfig(config: ChartConfigDto): ChartConfiguration {
    return {
      type: 'bar',
      data: {
        labels: config.labels,
        datasets:
            config.datasets.map((dataset, index) => ({
              label: dataset.label,
              backgroundColor: `${CHART_COLORS[index]}`,
              borderColor: `${CHART_COLORS[index]}`,
              data: dataset.data,
              barThickness: 'flex',
            }))
      },
      options: {
        indexAxis: 'y',
        plugins: {
          title: {
            display: true,
            text: 'Sites',
          },
          legend: {
            position: 'top',
          },
        },
        responsive: true,
        scales: {
          x: {
            stacked: true,
            position: 'top',
          },
          y: {
            stacked: true,
            grid: {
              display: false,
            },
          }
        },
      },
    }
  }
        <div class="modal-body">
          <canvas appChart [config]="config"></canvas>
        </div>

Thank you for help

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

0

There are two properties you can use to achieve.

  • barThickness
  • maxBarThickness

You can use maxBarThickness property in the dataset.

Here I'm attaching Stackblitz demo

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!