Google visualization 在谷歌图表中添加水平参考线';线条图

Google visualization 在谷歌图表中添加水平参考线';线条图,google-visualization,Google Visualization,我用它来显示一些数据(它可以工作) 图表显示了性能测试结果,这些结果不应超过某个值(例如,响应时间不应超过20ms)。我想画最大值(我猜是一条水平线),而不必添加新的(虚拟)数据系列 可能吗 非常感谢 Alban不,如果不添加另一系列数据,则无法添加另一行,但不必手动添加数据-数据视图足以为您计算: var maxResponseTime = 20; var view = new google.visualization.DataView(data); view.setColumns([0, 1

我用它来显示一些数据(它可以工作)

图表显示了性能测试结果,这些结果不应超过某个值(例如,响应时间不应超过20ms)。我想画最大值(我猜是一条水平线),而不必添加新的(虚拟)数据系列

可能吗

非常感谢


Alban

不,如果不添加另一系列数据,则无法添加另一行,但不必手动添加数据-数据视图足以为您计算:

var maxResponseTime = 20;
var view = new google.visualization.DataView(data);
view.setColumns([0, 1[, 2, 3, 4.... /* specify all of your existing columns here */, {
    type: 'number',
    calc: function () {
        return maxResponseTime;
    }
}]);

var chart = new google.visualization.LineChart(...);
chart.draw(view, {
    // options
    series: {
        // "n" should be the series index of the max line
        // typically this is column index - 1,
        // so if you have one domain column, one data series
        // and the max line, it would be:
        1: {
            visibleInLegend: false, // set this if you don't want it in the legend
            enableInteractivity: false // set this if you don't want the line to spawn tooltips
        }
    }
});

只是想一想:如果你不需要垂直轴的基线做任何其他事情,你可以将它设置为你的阈值来获得高亮显示的水平网格线。@dlaliberte,这不会影响其余的网格线吗?基线只是一个用粗体网格线高亮显示的值,它也不必是一条规则的网格线。如果基线值不是网格线,那么,是的,它可能会影响自动计算的网格线,但我还没有找到一个案例。它似乎可以完成这项工作。谢谢!