[英]How to add custom background to Google Charts
我設法通過在圖表頂部生成一個div(具有絕對位置)來達到這種效果。 還制作了一些JavaScript以重繪圖表並在選定的間隔內添加一條灰色線。
輸入功能:
function updateShader() {
// gets the entered values from the fields
var start = Math.round(parseInt(document.getElementById('startPos').value))
var width = Math.round(parseInt(document.getElementById('interval').value))
// draws the chart again with the entered filters
drawBasic(start, width);
//converts the entered values to ISH pixels
start = Math.round(start * 5.125)
width = Math.round(width * 5.125)
// special case when start = end point, so it will be grey on a little on both sides
if (start == width) {
start = start + 69
} else {
start = start + 73
}
// changes the "cover-box" to fit the entered values
document.getElementById('cover').style.marginLeft = start + "px";
document.getElementById('cover').style.width = width - start + 73 + "px";
}
封面盒的CSS:
#cover {
position:absolute;
width:0px;
height:124px;
margin-top:38px;
margin-left:73px;
pointer-events:none;
background: rgba(0, 0, 0, 0.5);
z-index:2;
}
有一些缺陷,例如它允許將“封面”框繪制在圖表外部,但總體而言,此解決方案是可行的。 也許還要進行一些用戶輸入檢查。
我還將工具提示更改為HTML,因此可以更改其z-index並通過它在封面框的頂部生成它。
最后, 完成小提琴 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.