渲染两个带有不同标签大小问题的chartjs甜甜圈

时间:2020-05-04 01:52:32

标签: css reactjs chart.js

我目前正在使用reactjs中的chartjs库渲染两个甜甜圈图。两个甜甜圈图都使用相同的 reusable 组件,但道具数据不同但样式相同。问题是第二张图表有五个标签,它决定将其尺寸调整为较小。

我已经测试过,如果我将第二个图表标签减少到两个,它们是相同的。标签越多,图表决定调整自身大小并弄乱我的中心文字样式的可能性就越大。

我期望的是

enter image description here

正在遇到问题:

enter image description here

我的甜甜圈图组件代码:

        <Doughnut 
          width={200}
          height={150} 
          data={data}
          options={{
            cutoutPercentage: 58,
            plugins: {
              outlabels: {
                backgroundColor: "white",
                borderColor: "none", 
                borderRadius: 0,
                borderWidth: 0, 
                color: "black",
                display: false,
                lineWidth: 1,
                padding: 0,
                lineColor: "black",
                textAlign: "center",
                stretch: 45,
              },
              datalabels: {
                display: false,
              },
              labels: false,
            },
            legend: {
              position: "right",
              align: "center",
              labels: {
                usePointStyle: true,

              }
            }
          }}
        />
        <div className="absolute-center text-center">
          <p className="donut-total">{data.total}</p>
          <p className="donut-text">{data.text}</p>
        </div>
      </div>

我的CSS:

    min-width: 200px;
    max-width: 400px;
    position: relative;
    margin-top: 30px;
    margin-bottom: 30px;
  }
  .absolute-center {
    position: absolute;
    top: 50%;
    left: 38%;
    transform: translate(-50%, -50%);
  }
  .text-center{
    text-align: center;
  }
  .donut-total {
    font-size: 20px;
    color: "#666666";
    font-family: $allianzNeo;
    font-weight: bold; 
  }
  .donut-text {
    font-size: 12px;
    color: "#666666";
    font-family: $allianzNeo;
  }

不显示错误消息。

0 个答案:

没有答案