在dygraphs中超过2 y轴

时间:2014-10-28 15:42:28

标签: javascript dygraphs

通过文档查看,我无法确定Dygraphs是否可以在图形输出上支持超过2 y轴?我需要绘制许多不同轴范围的曲线图。

1 个答案:

答案 0 :(得分:2)

似乎有可能。 This example似乎是通过使用axes和其他一些选项('labelName': { axis: {} }似乎创建了另一个Y轴)来使用它,但我还没有在文档中找到它。< / p>

但是当我尝试使用两个以上的Y轴时,我在日志中看到了这条消息:

dygraphs: Only two y-axes are supported at this time. (Trying to use 3) (stacktrace.js:31:25)

示例中的代码:

g = new Dygraph(
    document.getElementById("demodiv"),
    data, {
        labels: ['Date', 'Y1', 'Y2', 'Y3', 'Y4'],
        width: 640,
        height: 350,
        'Y3': {
            axis: {}
        },
        'Y4': {
            axis: 'Y3' // use the same y-axis as series Y3
        },
        xAxisLabelWidth: 100,
        yAxisLabelWidth: 100,
        axes: {
            x: {
                valueFormatter: function(ms) {
                    return 'xvf(' + new Date(ms).strftime('%Y-%m-%d') + ')';
                },
                axisLabelFormatter: function(d) {
                    return 'xalf(' + d.strftime('%Y-%m-%d') + ')';
                },
                pixelsPerLabel: 100,
            },
            y: {
                valueFormatter: function(y) {
                    return 'yvf(' + y.toPrecision(2) + ')';
                },
                axisLabelFormatter: function(y) {
                    return 'yalf(' + y.toPrecision(2) + ')';
                }
            },
            y2: {
                valueFormatter: function(y2) {
                    return 'y2vf(' + y2.toPrecision(2) + ')';
                },
                axisLabelFormatter: function(y2) {
                    return 'y2alf(' + y2.toPrecision(2) + ')';
                }
            }
        }
    }
);