https://developers.google.com/chart/interactive/docs/gallery/ganttchart
是否可以在甘特图持续时间上添加标签,如下面的屏幕截图所示?
最佳答案
正如 WhiteHat 所说,没有内置选项。 对于我的具体情况(我的甘特图中始终具有相同的结构),我执行了以下操作(将一些 DIV 放在条形顶部 - 使用这些 DIV,您可以做任何您想做的事情):
// callback after draw (afterDraw() function is called after chart is drawn)
google.visualization.events.addListener(chart, 'ready', afterDraw);
function afterDraw(){
// the container element to append our generated DIVs (with the labels)
// it has to be outside the SVG element, but inside the chart container
var toContainer = $('#chart_div > div > div');
// in order to create DIVs to place them on top of the bars, we first need to get bars SVG/RECTs positions and sizes
// in my case, the RECT elements with the necessary top/left/width/height are in the 6th G element
$( "#chart_div g:eq(5) rect" ).each(function() {
toContainer.append("<div style='top:"+$(this).attr('y')+"px; left: "+$(this).attr('x')+"px; width: "+$(this).attr('width')+"px; height: "+$(this).attr('height')+"px;text-align: center;position:absolute;line-height:2' >Some text</div>");
});
}
关于google-visualization - 谷歌可视化,向甘特图添加标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44189413/