reactjs - 如何使用 React-chartjs-2 设置条形图的轴标签样式
问题描述
我必须制作一个条形图,如上图所示,其圆角带有线性渐变背景,x 轴标签也应该有背景和圆角,使用 react-chartjs-2
我当前的代码是:Chart.js
import React from "react";
import { Bar } from "react-chartjs-2";
function Chart(props) {
return (
<div className="chart" style={{ width: "15rem", height: "15rem" }}>
<Bar
data={props.chartData}
options={{
ticks: {
stepSize: 25,
max: 100,
},
plugins: {
legend: {
display: false,
}
},
maintainAspectRatio: false,
borderRadius: 5,
scales: {
x: {
grid: {
display: false
}
},
y: {
grid: {
display: false
}
}
},
}}
/>
</div>
);
}
export default Chart;
该组件收到的道具是:
state = {
chartData: {}
};
componentWillMount() {
this.getChartData();
}
getChartData() {
this.setState({
chartData: {
labels: ["Age 5", "Age 10", "Age 15", "Age 35"],
datasets: [
{
data: [2, 15, 27, 100],
//backgroundColor:'green',
backgroundColor: [
"rgba(255, 99, 132, 0.6)",
"rgba(54, 162, 235, 0.6)",
"rgba(255, 206, 86, 0.6)",
"rgba(75, 192, 192, 0.6)",
]
}
]
}
});
}
解决方案
推荐阅读
- lightbox2 - 如何在 Lightbox v2.10.0 中链接 Youtube 视频
- docker - mesos + marathon组合中服务ip变化的解决方法能告诉我吗?
- java - 在杰克逊序列化后避免列表的类型信息
- angular - 异步修改数组 observable 中的每一项,并返回修改后的 observable
- javascript - 每隔几分钟编辑同一条消息
- php - 如何使用 PHP 代码将 XML 结果转换为 JSON 数组或 PHP 数组
- java - Postman 中应使用 ',' 而不是 't'
- java - 无法显示jsp页面
- microservices - 在 AWS ECS 上使用 Netflix Conductor Orchestration
- java - 将较大的数字向右移动,将较小的数字向左移动给定值