谷歌可视化,添加标签到甘特图

时间:2017-05-25 20:36:23

标签: google-visualization gantt-chart

https://developers.google.com/chart/interactive/docs/gallery/ganttchart

是否可以在甘特图表的持续时间上添加标签,如下面的截图?

enter image description here

1 个答案:

答案 0 :(得分:1)

正如WhiteHat所说,没有内置选项。 对于我的具体情况(我的Gantt图中总是有相同的结构)我做了以下操作(将一些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>");
    });

}