• <i id='ERnPO'><tr id='ERnPO'><dt id='ERnPO'><q id='ERnPO'><span id='ERnPO'><b id='ERnPO'><form id='ERnPO'><ins id='ERnPO'></ins><ul id='ERnPO'></ul><sub id='ERnPO'></sub></form><legend id='ERnPO'></legend><bdo id='ERnPO'><pre id='ERnPO'><center id='ERnPO'></center></pre></bdo></b><th id='ERnPO'></th></span></q></dt></tr></i><div id='ERnPO'><tfoot id='ERnPO'></tfoot><dl id='ERnPO'><fieldset id='ERnPO'></fieldset></dl></div>

        <bdo id='ERnPO'></bdo><ul id='ERnPO'></ul>
      <tfoot id='ERnPO'></tfoot>

      <small id='ERnPO'></small><noframes id='ERnPO'>

      <legend id='ERnPO'><style id='ERnPO'><dir id='ERnPO'><q id='ERnPO'></q></dir></style></legend>

        无法调整 react-chartjs-2 圆环图的大小

        Can#39;t resize react-chartjs-2 doughnut chart(无法调整 react-chartjs-2 圆环图的大小)
            <i id='3ElvR'><tr id='3ElvR'><dt id='3ElvR'><q id='3ElvR'><span id='3ElvR'><b id='3ElvR'><form id='3ElvR'><ins id='3ElvR'></ins><ul id='3ElvR'></ul><sub id='3ElvR'></sub></form><legend id='3ElvR'></legend><bdo id='3ElvR'><pre id='3ElvR'><center id='3ElvR'></center></pre></bdo></b><th id='3ElvR'></th></span></q></dt></tr></i><div id='3ElvR'><tfoot id='3ElvR'></tfoot><dl id='3ElvR'><fieldset id='3ElvR'></fieldset></dl></div>
            1. <tfoot id='3ElvR'></tfoot>

                <bdo id='3ElvR'></bdo><ul id='3ElvR'></ul>
                  <tbody id='3ElvR'></tbody>

                <small id='3ElvR'></small><noframes id='3ElvR'>

                  <legend id='3ElvR'><style id='3ElvR'><dir id='3ElvR'><q id='3ElvR'></q></dir></style></legend>
                  本文介绍了无法调整 react-chartjs-2 圆环图的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试用 react 和 gatsbyjs 制作一个甜甜圈图.该图表工作正常,但我无法让它使用 div 的整个宽度.对于保留的区域,它显示得太小.

                  I am trying to make a doughnut chart with react and gatsbyjs. The chart works fine but I can not get it to use the full width of the div. It displays too small for the area reserved.

                  render (){
                      return (
                  
                              <Doughnut 
                                  data={this.state.chartData}
                                  options={{
                                      padding:"0px",
                                      responsive:false,
                                      maintainAspectRatio:false,
                                      defaultFontSize:"14px",
                                      width:"400",
                                      height:"400",
                                      legend:{
                                          display:false,
                                      },
                                      plugins:{
                                          datalabels: {
                                              color:'#000000',
                                              anchor: "start",
                                              align:"end",
                                              formatter: function(value, context) {
                                                      return context.chart.data.labels[context.dataIndex];
                              }
                                          }
                                      } 
                                  }}
                                  />
                  
                  
                          )
                  
                  }
                  

                  推荐答案

                  看看 响应式下的">chartjs docs.

                  Have a look in the chartjs docs under responsive.

                  在选项中,设置responsive: true、maintainAspectRatio: true并去掉widthheight.

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

                  这是一个有效的 StackBlitz

                  这篇关于无法调整 react-chartjs-2 圆环图的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ChartJS Version 3 - common legend for multiple line charts(ChartJS 版本 3 - 多个折线图的常用图例)
                  Charts.js scales yaxes ticks min max doesnt work(Charts.js 缩放 yaxes 刻度 min max 不起作用)
                  How to expand the slice of donut chart in chartjs?(如何在chartjs中扩展圆环图的切片?)
                  Chart.js yAxes Ticks stepSize not working (fiddle)(Chart.js yAxes Ticks stepSize 不起作用(小提琴))
                  Rounded corners on chartJS v.2 - bar charts (with negative values)(chartJS v.2 上的圆角 - 条形图(带负值))
                  How to hide value in Chart JS bar(如何在 Chart JS 栏中隐藏值)

                    • <tfoot id='9p47C'></tfoot>

                          <bdo id='9p47C'></bdo><ul id='9p47C'></ul>
                        • <i id='9p47C'><tr id='9p47C'><dt id='9p47C'><q id='9p47C'><span id='9p47C'><b id='9p47C'><form id='9p47C'><ins id='9p47C'></ins><ul id='9p47C'></ul><sub id='9p47C'></sub></form><legend id='9p47C'></legend><bdo id='9p47C'><pre id='9p47C'><center id='9p47C'></center></pre></bdo></b><th id='9p47C'></th></span></q></dt></tr></i><div id='9p47C'><tfoot id='9p47C'></tfoot><dl id='9p47C'><fieldset id='9p47C'></fieldset></dl></div>
                            <tbody id='9p47C'></tbody>

                        • <legend id='9p47C'><style id='9p47C'><dir id='9p47C'><q id='9p47C'></q></dir></style></legend>

                            <small id='9p47C'></small><noframes id='9p47C'>