Chart width and height not working
See original GitHub issueI am testing this library to create a chart for an app. I saw the sample dataset below from this tutorial.
import React, { Component } from 'react'
import { Line } from 'react-chartjs-2'
class CurrencyChart extends Component {
render() {
const chartData = {
labels: ['M', 'T', 'W', 'T', 'F', 'S', 'S'],
datasets: [{
label: 'apples',
data: [12, 19, 3, 17, 6, 3, 7],
backgroundColor: "rgba(153,255,51,0.6)"
}, {
label: 'oranges',
data: [2, 29, 5, 5, 2, 3, 10],
backgroundColor: "rgba(255,153,0,0.6)"
}]
}
return (
<Line data={chartData} width={600} height={250}></Line>
)
}
}
export default CurrencyChart
I added bootstrap and jquery from a cdn in the html file. This is the output (The buttons on the top come from the parent component):
I tried using the chart.js without the react-chartjs-2 package but it is either not being rendered or with no background color.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:12
Top Results From Across the Web
Setting width and height [closed] - Stack Overflow
Show activity on this post. This works. The key here is to use an outer div and set the width and height on...
Read more >Responsive Charts - Chart.js
When it comes to changing the chart size based on the window size, a major limitation is that the canvas render size (...
Read more >Chartjs taking canvas width and height attribute, but ignoring ...
For non responsive charts, some work has been done in #3356: style width and height are now used to initialize the canvas size...
Read more >Chart.js chart with fixed height and variable width - CodePen
Chart.js chart with fixed height and variable width. Adjust the width of the window to test.
Read more >Why doesn't the chart maintain its width/height? - react-chartjs-2
In order for Chart.js to obey the custom size you need to set maintainAspectRatio to false:
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
hello, simply you add this in options: <Pie data={state} width={10} height={5} options={{maintainAspectRatio: false}} />
hey @tiagofumo ,
Have you tried with https://github.com/gor181/react-chartjs-2#custom-size ?