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

470
Views
Chart.js: How to set minimum height of chart but still maintain aspect ratio?

How can I set a fixed aspect ratio to the chart but also set a minimum height so that it behaves like below:

enter image description here

I have tried using react-chartjs-2:

<div
  style={{
    minHeight: 300,
    paddingTop: "33.33333%",
  }}
>
  <Bar
    style={{ width: "100%", height: "100%" }}
    //data={...}
    options={{
      maintainAspectRatio: false,
    }}
  />
</div>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Solved it by adding an intermediate div between container and chart:

<div
  style={{
    minHeight: 300,
    paddingTop: "33.33333%",
    position: "relative",
  }}
>
  <div
    style={{
      position: "absolute",
      inset: 0,
    }}
  >
    <Bar
      style={{ width: "100%", height: "100%" }}
      //data={...}
      options={{
        maintainAspectRatio: false,
      }}
    />
  </div>
</div>
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!