繁体   English   中英

在Highcharts.js中设置两个yAxis的问题

[英]Issue on Setting Two yAxis in Highcharts.js

您能否看一下这个演示 ,让我知道为什么我也无法设置另一面yAxis?

$(function () {
            $('#chart2').highcharts({
        chart: {
            type: 'column'
        },
         credits: {
            enabled: false
        },
            title: {
            text: 'The Chart Title Goes Here!',
              style: {
                color: '#5882FA',
                fontWeight: 'normal',
                fontSize: '11',
                marginBottom: '30'
            }
        },

        xAxis: {
            categories: ['Roads', 'Powerlines'],

        },
                  yAxis: [{ // Primary yAxis
                labels: {
                    format: '{value}°C',
                    style: {
                        color: Highcharts.getOptions().colors[1]
                    }
                },
                title: {
                    text: 'Temperature',
                    style: {
                        color: Highcharts.getOptions().colors[1]
                    }
                }
            }, { // Secondary yAxis
                title: {
                    text: 'Rainfall',
                    style: {
                        color: Highcharts.getOptions().colors[0]
                    }
                },
                labels: {
                    format: '{value} mm',
                    style: {
                        color: Highcharts.getOptions().colors[0]
                    }
                },
                opposite: true
            }],
        legend: {
        enabled: false
    },
         tooltip: {
            formatter: function() {
                return this.x +
                    ' is <b>'+ this.y +'</b>';
            }
        },

        series: [{
            data: [{
                name: 'Roads',

                y: 200
            }, {
                name: 'Powerlines',
                color: '#FF00FF',
                y: 50
            }]
        }]
    });
});

我在Highcharts API上找到了一些示例,并尝试在我的演示中关注它们,但是它们没有用!

高图:具有多个y轴的条形图

好吧,我认为您需要修复series对象。 怎么样这个

series : [{
        data : [{
                name : 'Roads',

                y : 200
            }, {
                name : 'Powerlines',
                color : '#FF00FF',
                y : 50
            }
        ]
    },
    {
        yAxis : 1,
        data : [{
                name : 'Roads',

                y : 30
            }, {
                name : 'Powerlines',
                color : '#FF00FF',
                y : 10
            }
        ]
    }
]

另外,您需要向轴添加yAxis : 1作为ID (可以明确设置轴的ID以确保)

我已更正了您的代码的问题: DEMO

您将必须分别传递每个y轴的序列数据:

series: [{
            name: 'Rainfall',
            type: 'column',
            yAxis: 1,
            data: [49.9, 71.5],
            tooltip: {
                valueSuffix: ' mm'
            }

        }, {
            name: 'Temperature',
            type: 'column',
            data: [7.0, 6.9],
            tooltip: {
                valueSuffix: ' °C'
            }
        }]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM