以编程方式更改瞄准图的标题

时间:2015-06-08 00:06:03

标签: dygraphs

当用户点击图表时,我无法以编程方式更改dygraph图表的标题。我能够获得他们点击的价值,但我似乎无法更改title属性。这是我正在尝试的内容:

clickCallback: function (e, p, points) {
    for (var i = 0; i < dygraphs.length; i++) {
        var g = dygraphs[i];

        var pos = Dygraph.findPos(g.graphDiv);
        var canvasx = Dygraph.pageX(e) - pos.x;
        var canvasy = Dygraph.pageY(e) - pos.y;
        var xy = g.toDataCoords(canvasx, canvasy);
        var x = xy[0];
        var rows = g.numRows();
        var closestRow = -1;
        var smallestDiff = -1;

        for (var row = 0; row < rows; row++) {
            var date = g.getValue(row, 0); // millis
            var diff = Math.abs(date - x);
            if (smallestDiff < 0 || diff < smallestDiff) {
                smallestDiff = diff;
                closestRow = row;
            }
        }

        if (closestRow != -1) {
            //Update the marker label
            var text = g.rawData_[closestRow][1];

            g.updateOptions({
                title: text
            }, true);
        }
    }
}

这是我的&#34;破坏&#34;的链接版。不确定是否重要,但我使用的是1.1.1: http://jsfiddle.net/ye97owtm/2/

0 个答案:

没有答案