score:4
import React, { Component } from 'react';
import { render } from 'react-dom';
import Hello from './Hello';
import './style.css';
import { Doughnut } from 'react-chartjs-2'
class App extends Component {
constructor() {
super();
this.state = {
name: 'React',
data: {
datasets: [{
data: [10, 20, 30]
}],
labels: [
'Red',
'Yellow',
'Blue'
]
}
}
}
render() {
return (
<Doughnut
data={this.state.data}
options={{
responsive: true,
maintainAspectRatio: false,
}}
/>
)
}
}
render(<App />, document.getElementById('root'));
score:13
Have a look in the chartjs docs under responsive.
In the options, set responsive: true, maintainAspectRatio: true
and remove width
and height
.
import React, { Component } from 'react';
import { render } from 'react-dom';
import Hello from './Hello';
import './style.css';
import { Doughnut } from 'react-chartjs-2'
class App extends Component {
constructor() {
super();
this.state = {
name: 'React',
data: {
datasets: [{
data: [10, 20, 30]
}],
labels: [
'Red',
'Yellow',
'Blue'
]
}
}
}
render() {
return (
<Doughnut
data={this.state.data}
options={{
responsive: true,
maintainAspectRatio: true,
}}
/>
)
}
}
render(<App />, document.getElementById('root'));
Here is a working StackBlitz
Source: stackoverflow.com
Related Query
- Can't resize react-chartjs-2 doughnut chart
- how to get React chartjs to resize back down with window
- React ChartJS 2 : Get data on clicking the chart
- Chartjs doughnut chart with gradient color
- Stacked bar chart starting from 0 - ChartJS React
- Add Text to Doughnut Chart - ChartJS
- React component wont re-render ChartJS chart with redux props
- Force ChartJS to show Doughnut chart with null values
- Small value in doughnut chart is not visible - Chartjs
- ChartJs - Round borders on a doughnut chart with multiple datasets
- Chartjs - how to change the notation of doughnut chart
- Chartjs React Typescript moving x axis labels above chart
- cant resize range of Y axis of chart in HTML/PHP
- hide label on doughnut chart of chartjs
- Chartjs doughnut chart rounded corners for half doghnut
- React Chartjs - Update Chart on interval
- React with chart js, labelling problems in multiple datasets for doughnut chart
- Chartjs Doughnut Chart smooth animation in countdown
- ChartJS : Hook before values are given to doughnut (absolute value in chart and real values in the tooltips)
- I cant get Legend to work for my chartjs donut chart
- Resize Chart Independently From Legend in ChartJS for Canvas Download
- When I added a funnel chart to chartjs all the charts are load compressed until resize page
- Label issue in doughnut chart using chartjs
- ChartJs 2 How to remove numbers from the doughnut chart on loading
- Trying to export chart with Chartjs and React but getting erorr
- ChartJS custom doughnut chart not showing in version 2.6.0
- Dynamically loaded chart data not showing Chartjs React
- ChartJS custom legend doughnut separate legend from chart area
- ChartJS doughnut chart not displaying colours
- How to set up a simple pie chart using React in ChartJS on codesandbox
More Query from same tag
- ChartJS Doughnout Chart Pie Offset on Hover
- ChartJS/High Charts Radar chart - Different radial axis labels for each category that appear on hover
- How to reorganize data to display how many times a string appears in an array object?
- How to set specific height for chartJs background color in terms of yAxis value
- Failed to use Chart.js using Angular2
- How to hide Fields and Strike-through Legends when the data is empty or Zero in Pie/Polar/Doughnut Chart?
- How to Push data dynamically from firebase to bar graph in angular
- Chart.js bar chart barWidth is Inconsistent
- Chart is not defined Node.js Chart.js
- Chartjs 2 Line Graph Single Stroke Between Datasets
- ChartJS - adding scroll to horizontal legend in Line chart
- chart js not dispalying data array that comes from an axios request
- How to disable canvas elements from hijacking mouse wheel when scrolling through a page?
- How to sort XY line chart tooltip items based on value and add thousands separators?
- Multiple Graphs on one page
- ChartJS Radar Chart radar lines color?
- Age pyramid: 3.5.1 chartjs
- Chartjs doughnut chart for conditional data
- Chart JS change pointBackgroundColor based on data value
- Charts.js graph not displaying
- Trouble setting options for radar chart on Quickchart.io
- ChartJS line chart drag and zoom
- How to show both overlapping lines in in chartjs
- add labels dynamically in Charts.js
- vue-chartjs cannot display the labels and datasets
- Chart.js - get x-axis label (or index) in onHover event
- Pass Data From Node/Express to Front-End Javascript
- Multi Level Color in Doughnut Chart in ng2-charts
- Changing line color below specific value in Chart.js
- Not able to change chart.js x and y font colors