reactjs / react-chartjs

common react charting components using chart.js
MIT License
2.93k stars 301 forks source link

Set Global Property to Responsive or Canvass Width to 100% #118

Closed switmac closed 6 years ago

switmac commented 8 years ago

Hello,

Is there anyway for me to set the canvass width to 100% to make it responsive? Or how can I set the global property to responsive using ecma6 in React.

Here is my sample usage of the API.

import {Line} from 'react-chartjs';

class Chart extends Component {
    render(){
         return (
             <div className="chart">
                 <Line data={this.state.data}  options={this.state.options} width={this.props.width} height={this.props.height}/>
              </div>
         );
    }
}
rublev commented 8 years ago

Set the width on your graph container, then set the width of your canvas element to 100% using css width: 100% !important.

Set these global chart options to:

responsive: true,
maintainAspectRatio: false,
jsina commented 5 years ago

I've done it with this code. although I've use the chart.js for showing on WebView on my application. <canvas style="width: 100% !important;height: auto !important;" id="canvas">