react-chartjs-2 icon indicating copy to clipboard operation
react-chartjs-2 copied to clipboard

width and height do not work for me

Open DimaXu opened this issue 10 years ago • 16 comments

I like this library very much. But in my testing with [email protected] and [email protected], the width and height do not work for me. I set them as 300 and 200 respectively, the result was that the pie and Doughnut occupied the whole width of the page. I wonder whether something is wrong with my code or anything else in this library. Any response will be appreciated.

my code is: <Pie data={this.phyiscalMemory} width={300} height={200} options={{ maintainAspectRatio: false }} />

screenshot from 2016-10-05 12 14 19

DimaXu avatar Oct 04 '16 23:10 DimaXu

It should not be committed as an issue.

DimaXu avatar Oct 05 '16 01:10 DimaXu

What was the fix here? I'm having the same issue.

iarry avatar Nov 09 '16 22:11 iarry

hey @iarry

have you tried https://github.com/gor181/react-chartjs-2#custom-size ?

Cheers,

gor181 avatar Nov 09 '16 22:11 gor181

Yep, I set maintainAspectRatio: false. I can make the graph grow larger, but it won't go below 497px x 200px

iarry avatar Nov 09 '16 23:11 iarry

I managed to change the width and height with CSS on the canvas, but it needed !important tags.

iarry avatar Nov 09 '16 23:11 iarry

This still is an ongoing issue for me. I used maintainAspectRatio: false in the options while trying to specify the height and width of a Line chart. The height works correctly but the width won't change. I had to put this Line in a div that has the appropriate width.

return (
    <div style={{width: '400px'}}>
        <Line
            data={data}
            options={options}
            height={200}
            width={400}
        />
    </div>
)

alexisthual avatar Aug 05 '17 15:08 alexisthual

Did anybody find a way to fix this issue? I mean by passing the width and height directly as props?

<Pie
	data={data}
	width={100}
	height={50}
	options={{
		maintainAspectRatio: false
	}}
/>

doesn't work at all. The canvas width and height is always 678 and 948.

huyvohcmc avatar Feb 12 '18 05:02 huyvohcmc

I have the same issue, using Pie.

solaomosola avatar Feb 15 '18 10:02 solaomosola

I'm having this same issue, the height is respected but the width is ignored:

<Line data={data} width={200} height={200} options={{ maintainAspectRatio: false }} />

MikeRoberts2008 avatar Feb 27 '18 12:02 MikeRoberts2008

I have same issue, using doughnut

nhuthan avatar Feb 28 '18 15:02 nhuthan

try <Line data={data} width={200} height={200} options={{ maintainAspectRatio: false ,responsive:false }} />

KennethChiu123 avatar Sep 06 '18 23:09 KennethChiu123

when i decrease the width the screen , the graph width can't change but height will change . I tired many solution nothing works

jayaramsurya avatar Nov 28 '18 05:11 jayaramsurya

May be this can help https://github.com/jerairrest/react-chartjs-2/issues/334#issuecomment-455153566

cention-sany avatar Jan 17 '19 12:01 cention-sany

@KennethChiu123

<Line data={data} width={200} height={200} options={{ maintainAspectRatio: false }} /> This worked for me. responsive:false was not necessary for me.

Thank you.

DPTeamMember avatar Jun 09 '21 13:06 DPTeamMember

data={data} width={200} height={200} options={{ maintainAspectRatio: false ,responsive:false }}

This solution worked for me but also this: <Bar data={data} width={1900} height={900} options={{maintainAspectRatio: true, responsive: true}}/>

alex-drocks avatar Sep 12 '21 13:09 alex-drocks

This is the solution https://react-chartjs-2.js.org/faq/maintain-aspect-ratio/

shubhamsharma2k avatar Jul 15 '23 16:07 shubhamsharma2k