charts - 条形图背景操作
解决方案
没有可用于更改网格线宽度的配置选项。
但是,您可以手动更改图表的'ready'
事件。
请参阅以下工作片段...
在这里,次要网格线被移动以与轴标签对齐。
并且宽度增加到下一个轴标签的位置。
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = google.visualization.arrayToDataTable([
['X', 'Y'],
['school_score', 80],
['salary_score', 72],
['benefits_score', 50],
['work_environment', 42],
['security_score', 35]
]);
var container = document.getElementById('chart');
var chart = new google.visualization.BarChart(container);
google.visualization.events.addListener(chart, 'ready', function () {
// find gridlines
var gridlines = container.getElementsByTagName('rect');
var minor = [];
Array.prototype.forEach.call(gridlines, function(gridline) {
if ((gridline.getAttribute('width') === '1') && (gridline.getAttribute('fill') === '#ebebeb')) {
minor.push(gridline);
}
});
// increase width of every other minor gridline, make the rest transparent
var index = 0;
var labelBounds;
var labelBoundsNext;
var chartLayout = chart.getChartLayoutInterface();
while ((labelBounds !== null) && (index < minor.length)) {
if (index % 2 === 0) {
// use axis label bounds to determine width
labelBounds = chartLayout.getBoundingBox('hAxis#0#label#' + index);
labelBoundsNext = chartLayout.getBoundingBox('hAxis#0#label#' + (index + 1));
minor[index].setAttribute('x', labelBounds.left);
minor[index].setAttribute('width', (labelBoundsNext.left - labelBounds.left + labelBounds.width));
} else {
minor[index].setAttribute('fill', 'transparent');
}
index++;
}
});
chart.draw(data);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart"></div>
推荐阅读
- c# - C# dll System.Reflection.TargetInvocationException 错误
- github - 如何为我的 GitHub 存储库提供多个彩色圆圈“技术徽章”?
- azure - 如何使用 terraform 将 Azure 应用服务与应用程序洞察资源(新的或现有的)相关联?
- reactjs - 尝试在 Windows 10 中安装 react js。但我每次都收到此错误
- python - 使用转换函数将列值转换为浮点数
- ios - 使用swift从tableview中删除行
- python - Visual Studio Code 和 Jinja 模板
- react-admin -
和 的 React Admin 生成错误的输出 - java - Google Places Autocomplete无法加载搜索结果android studio
- excel - 创建一个宏来取消隐藏工作表和清除使用的行,重置工作簿