React-chartjs-2: width and height do not work for me

Created on 5 Oct 2016  路  13Comments  路  Source: reactchartjs/react-chartjs-2

I like this library very much. But in my testing with [email protected] and chart.[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:
data={this.phyiscalMemory}
width={300}
height={200}
options={{
maintainAspectRatio: false
}}
/>

screenshot from 2016-10-05 12 14 19

Most helpful comment

try

All 13 comments

It should not be committed as an issue.

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

hey @iarry

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

Cheers,

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

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

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>
)

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.

I have the same issue, using Pie.

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 }} />

I have same issue, using doughnut

try

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

Was this page helpful?
0 / 5 - 0 ratings