google-visualization - 谷歌可视化,向甘特图添加标签

标签 google-visualization gantt-chart

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

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

enter image description here

最佳答案

正如 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/

相关文章:

javascript - 将 Google Chart 保存为 SVG?

google-sheets - 创建自动更新甘特图

c++ - 寻找第 3 方 Qt 甘特图组件

python - 在 plotly 中使用数值创建甘特图

javascript - 将 Google 图表包装器保存到图像

ios - 仅将 Y 轴粘贴在 Google 实时图表上的一个位置

javascript - 我的 Google 饼图中未对齐的标签/切片文本

html - 如何通过 Google Visualization API 将表格中的数字居中?

python - 在plotlyexpress中添加甘特图的超链接?

jquery - 如何使用 jQuery 创建类似于甘特图的图表?