javascript - 修改谷歌图表中的最大值
问题描述
我想制作一个电子邮件点击率图表,这个 CTR 的值从0.5
到非常小100
,但是当我将它显示在具有 10 000 个值(每天发送的电子邮件)的条形旁边时,小的 CTR 条/线也是图表低且不可见。
我需要为这个 CTR 值指定一个最小值/最大值,以便在图表的最顶部,100
例如,我需要在这个默认的谷歌代码中修改什么,其中平均线可以是我的 CTR 率? 0.5
所以我让那条线转到100
解决方案
将 CTR 放在辅助轴上,
并在那里设置最小值和最大值
series: {
5: {
targetAxisIndex: 1, // <-- set as secondary axis
type: 'line'
}
},
vAxes: { // <-- use vAxes for secondary axis options
1: {
title: 'Average',
viewWindow: { // <-- set view window
min: 0,
max: 100
}
}
}
请参阅以下工作片段...
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = google.visualization.arrayToDataTable([
['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua New Guinea', 'Rwanda', 'Average'],
['2004/05', 10165, 12938, 10522, 15998, 14450, 0.6],
['2005/06', 10135, 13120, 11599, 11268, 12288, 20.6],
['2006/07', 11157, 10167, 12587, 12807, 13397, 40.9],
['2007/08', 12139, 11110, 11615, 10968, 12215, 80.4],
['2008/09', 13136, 11691, 10629, 11026, 13366, 90.6]
]);
var options = {
title : 'Monthly Coffee Production by Country',
vAxis: {title: 'Cups'},
hAxis: {title: 'Month'},
seriesType: 'bars',
series: {
5: {
targetAxisIndex: 1,
type: 'line'
}
},
vAxes: {
1: {
title: 'Average',
viewWindow: {
min: 0,
max: 100
}
}
}
};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
chart.draw(data, options);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
推荐阅读
- delphi - 我可以将图表分成不相等的部分吗?
- .net-core - 使用 Bot Framework V4 在 Teams 中发送主动式 1:1 消息
- css - CSS无法对齐垂直/水平定位在绝对位置的img
- python - 为什么比较两个 Numpy 数组时会出现此错误?
- c# - TabControl 事件 SelectionChanged 在同一项目上更改时执行了两次
- sockets - 如何处理python中的套接字异常并继续执行脚本?
- typescript - TypeScript 3.x:访问未知类型的属性
- autodesk-forge - 等待 DeleteForgeAppAsync 继续
- heroku - 如何查看 Heroku 应用程序何时被删除?
- mysql - 将 Woocommerce 产品简短描述复制到 ACF