react-google-charts - 调整谷歌图表的大小以同样适合所有组件
问题描述
我正在使用ComboChart
图书馆React Google Chart
。这是我的功能组件的外观:
import React from 'react';
import { Chart } from 'react-google-charts';
export default function TimeSeriesChart({
vAxisTitle,
vAxisSecondTitle,
hAxisTitle,
dataHeaders,
barColors,
}) {
return (
<Chart
chartType='ComboChart'
loader={<div>Loading Chart</div>}
data={[
dataHeaders,
['July 1, 2021', 165, 938],
['July 2, 2021', 135, 1120],
['July 3, 2021', 157, 1167],
['July 4, 2021', 139, 1110],
['July 5, 2021', 136, 691],
]}
options={{
// title: 'Reach Plot',
series: {
0: { targetAxisIndex: 0 },
1: { targetAxisIndex: 1, type: 'line' },
},
vAxes: {
// Adds titles to each axis.
0: { title: vAxisTitle },
1: { title: vAxisSecondTitle },
},
chartArea: {
// leave room for y-axis labels
width: '70%',
},
colors: barColors,
width: '99%',
hAxis: { title: hAxisTitle, gridlines: { count: 4 } },
backgroundColor: '#fff',
seriesType: 'bars',
legend: {
position: 'top',
alignment: '',
},
}}
rootProps={{ 'data-testid': '1' }}
/>
);
}
我正在努力调整宽度,如下所示:
chartArea: {
// leave room for y-axis labels
width: '70%',
}
当我将图表区域宽度设置70%
为时,它允许我查看 ylabels,如下所示:
但它会切断 x 轴标签,因为您可以看到它们折叠为...
s。而当我将宽度提高到 90% 时,它会覆盖 x 轴标签,但会折叠我的 y 轴标签:
chartArea: {
// leave room for y-axis labels
width: '90%',
}
如何创建涵盖两种情况的最佳情况?
解决方案
推荐阅读
- c++ - C++中模板化异常类的多重继承
- c# - 如何从 C# 中的下拉列表控件中删除项目
- c - 如何使用 C 宏定义 PIC 单片机引脚名称?
- kotlin - 具有泛型类型的 Kotlin 二级构造函数
- linux - 脚本显示未找到进程,而它存在
- database - MS Access:使用 VBA 使用多选列表框更改查询
- laravel - 在 laravel nova 中注册公共 api 路由,无需身份验证
- android - 我应该将 ViewModel 与 UseCase 一起使用吗?
- c# - ASP.NET:当 http 状态为 4xx 时,Webmethos 不返回有效负载
- amazon-web-services - 如何更快地在 AWS 上发布无服务器应用程序?