reactjs - 在reactjs甜甜圈图中,如何减小图表的宽度
问题描述
甜甜圈图的宽度没有减少..如何减少它
graphData :{
datasets:[
{
label : 'Customer Expense Analysis',
data : [50,20],
backgroundColor: [' #ffeb00','#a2a2a2'],
hoverBackgroundColor:['#ffeb00','#a2a2a2'],
labels: ["Free Parking Slot", "Total Parking Slot"],
borderColor:'#363A42',
boredrAlign: 'center',
borderWidth: 1,
cutoutPercentage:0
}
]
},
<Doughnut
data= {this.state.graphData}
options={{
title: {
display: this.props.displayTitle,
fontSize: 40
},
maintainAspectRatio: true,
legend: {
display: true,
position: "left",
}
}}
/>
边框宽度增加了但是图中两个数据之间的距离增加了宽度怎么办???
解决方案
你需要像这样传递宽度<Doughnut data={data} width={600} />
这是一个代码:
import React from "react";
import { Line, Doughnut } from "react-chartjs-2";
const data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [
{
label: "My First dataset",
fill: false,
lineTension: 0.1,
backgroundColor: "rgba(75,192,192,0.4)",
borderColor: "rgba(75,192,192,1)",
borderCapStyle: "butt",
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: "miter",
pointBorderColor: "rgba(75,192,192,1)",
pointBackgroundColor: "#fff",
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: "rgba(75,192,192,1)",
pointHoverBorderColor: "rgba(220,220,220,1)",
pointHoverBorderWidth: 2,
pointRadius: 1,
pointHitRadius: 10,
data: [65, 59, 80, 81, 56, 55, 40]
}
]
};
export default class Hello extends React.Component {
render() {
return (
<div>
<h2>Line Example</h2>
<Doughnut data={data} width={600} />
</div>
);
}
}
在代码沙盒上运行代码
让我知道它是否有效。
此外,如果您想要响应式图表。这是指南:
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'));
推荐阅读
- android - 在android应用程序中硬编码用户名和密码
- javascript - Jenkins CI E2E:不禁用量角器和硒指定的Firefox下载弹出窗口
- r - 在闪亮服务器上使用来自闪亮日志的 store_json() 的问题
- sql-server - 我们如何计算每天最后三天订购的唯一用户 ID?
- graphql - 在 apollo-client 的 useQuery 中使用 fetchPolicy='cache-and-network' 不会更新 fetch 上的缓存更多
- python - Selenium - 断言元素存在
- python - CV2,更改 .mp4 文件的编解码器?
- git - git 在静默/安静/非详细模式下恢复?
- android - 新的 Xamarin Forms 4.6 MediaElement 不适用于 Android
- c# - Blazor CascadingValue 以编程方式