Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
-2
rated 0 times [  5] [ 7]  / answers: 1 / hits: 10590  / 3 Years ago, mon, february 1, 2021, 12:00:00

I am using Horizontal Bar from react-chart-js (https://github.com/reactchartjs/react-chartjs-2/blob/react16/example/src/charts/HorizontalBar.js) as below,


  const data = {
label: ["graph"],
datasets: [
{
label: "A",
backgroundColor: "red",
data: [50],
},
{
label: "B",
backgroundColor: "yellow",
data: [10],
},
],
};

const chartOptions = {
scales: {
xAxes: [
{
stacked: true,
barPercentage: 0.2,
},
],
yAxes: [
{
stacked: true,
barPercentage: 0.2,
},
],
},
};

and


<div>
<HorizontalBar data={data} options={chartOptions}/>
</div>

I tried applying height on to div or horizontal bar directly to restrict scaling up of the canvas but it dint solve though. Is it possible to supply height and width to the canvas of chart respectively.


More From » reactjs

 Answers
17

In my case, setting
maintainAspectRatio:false along with supplying height/width on div


<div style={{height:'100px',width:'200px'}}>
<HorizontalBar data={data} options={chartOptions}/>
</div>

helped in restricting the canvas's scalability.


Relevant Source: https://www.chartjs.org/docs/latest/general/responsive.html#important-note


[#1850] Thursday, January 28, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bradleymoisesy

Total Points: 121
Total Questions: 105
Total Answers: 95

Location: Nepal
Member since Mon, Jan 4, 2021
3 Years ago
bradleymoisesy questions
Wed, Dec 22, 21, 00:00, 2 Years ago
Tue, Jun 1, 21, 00:00, 3 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
Thu, Jan 16, 20, 00:00, 4 Years ago
;