HighCharts.正在将id为的系列添加到yAxis

HighCharts. Adding series to yAxis with id

本文关键字:系列 添加 yAxis id HighCharts      更新时间:2023-09-26

我在将序列添加到高图中ID不同的yAxis时遇到了一些问题。

我举了一个例子:

$(function () {
        $('#graf').highcharts({
            chart: {
                zoomType: 'xy'
            },
            title: {
                text: ''
            },
            subtitle: {
                text: ''
            },
            xAxis: [{type: 'datetime',
                    title: {
                        text: 'Date'
                    }}],
            yAxis: [],
                    series : []
                    ,
            tooltip: {
                shared: true
            },
            legend: {
                enabled: true,
                align: 'left',
                backgroundColor: '#FFFFFF',
                borderColor: 'grey',
                borderWidth: 1,
                layout: 'vertical',
                verticalAlign: 'top',
                y: 0,
                shadow: true
            }
        });

var chart = $('#graf').highcharts();
$('#add').click(function () {
    chart.addAxis({ // Secondary yAxis
        id: "asd",
        title: {
            text: 'Rainfall'
        },
        lineWidth: 2,
        lineColor: '#08F',
        opposite: true
    });     
    chart.addAxis({ // Secondary yAxis
        id: "abc",
        title: {
            text: 'Rainfall'
        },
        lineWidth: 2,
        lineColor: '#08F',
        opposite: true
    });     
    chart.addSeries({
        name: 'Rainfall',
        type: 'column',
        color: '#08F',
        yAxis: "asd",
        data: [ [Date.UTC(1970,  9, 27), 0   ],
            [Date.UTC(1970, 10, 10), 0.6 ],
            [Date.UTC(1970, 10, 18), 0.7 ],
            [Date.UTC(1970, 11,  2), 0.8 ],
            [Date.UTC(1970, 11,  9), 0.6 ]]
    });
    $(this).attr('disabled', true);
    $('#remove').attr('disabled', false);
});
});

JSFIDDLE:http://jsfiddle.net/5f6b6mu9/

我有id为"asd"answers"abc"的yAxis。当试图将序列添加到"asd"y轴时,它不起作用。未捕获的类型错误:无法读取未定义的属性"length"。

以下是我的网页中发生的事情:http://i61.tinypic.com/8yx7cw.jpg

如果我把两个yaxis id都改为同一个id,这是有效的,但这不是重点。

有什么建议吗?感谢

这很简单。

添加序列后立即添加与yAxis对应的序列。

chart.addAxis({ // Secondary yAxis
            id: "asd",
            title: {
                text: 'Rainfall'
            },
            lineWidth: 2,
            lineColor: '#08F',
            opposite: true
        },false);
        chart.addSeries({
            name: 'Rainfall',
            type: 'column',
            color: '#08F',
            yAxis: "asd",
            data: [ [Date.UTC(1970,  9, 27), 0   ],
                [Date.UTC(1970, 10, 10), 0.6 ],
                [Date.UTC(1970, 10, 18), 0.7 ],
                [Date.UTC(1970, 11,  2), 0.8 ],
                [Date.UTC(1970, 11,  9), 0.6 ]]
        });
        chart.addAxis({ // Secondary yAxis
            id: "abc",
            title: {
                text: 'Rainfall'
            },
            lineWidth: 2,
            lineColor: '#08F',
            opposite: true
        },false); 

在这里,我更新了你的小提琴