简体   繁体   English

如何使用两个yAxis删除高图表图中的间隙

[英]How to remove a gap in high charts graph with two yAxis

I have been trying to get rid of the gap on the left and nothing works. 我一直试图摆脱左边的差距,没有任何作用。 This issues only happens when I add a reverse yAxis on the right. 只有当我在右侧添加反向yAxis时才会出现此问题。 Below is the code I am using: 以下是我使用的代码:

$(function () {
    var categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
    $('#container').highcharts({
        chart: {
            type: 'areaspline',
            zoomType: 'xy',
        },
        title: {
            text: 'Stats',
        },
        subtitle: {
            text: 'YTD 2013 - 2014',
        },
        xAxis: {
            labels: {
                enabled: true,
                formatter: function () {
                    return categories[this.value];
                }
            },
            tickInterval: 1,
            minPadding: 0,
            maxPadding: 0,
            startOnTick: true,
            endOnTick: true,
        },
        yAxis: [{ //--- Primary yAxis
            min: 0,
            minPadding: 0,
            maxPadding: 0,
            startOnTick: true,
            endOnTick: true,
            title: {
                text: 'Mds',
                style: {
                    color: '#8dc63f',
                }
            },
            labels: {
                style: {
                    color: '#8dc63f',
                    fontWeight: 'bold'
                }
            }
        }, { //--- Secondary yAxis


            labels: {
                formatter: function () {
                    var mil = '$';
                    return mil + Highcharts.numberFormat(this.value, 0);
                },
                style: {
                    color: '#3fb4ed',
                    fontWeight: 'bold'
                }
            },
            title: {
                text: 'Revenue',
                style: {
                    color: '#3fb4ed',
                }

            },
            opposite: true
        }],
        series: [{
            type: 'areaspline',
            color: '#005a84',
            fillOpacity: 0.2,
            yAxis: 0,
            zIndex: 3,
            name: 'Goals',
            data: [5, 5, 5, 5, 6, 8, 8, 8, 10, 10, 10, 10],
        }, {
            type: 'areaspline',
            color: '#8dc63f',
            fillOpacity: 0.2,
            yAxis: 0,
            zIndex: 4,
            name: 'This Year',
            data: [21, 14, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        }, {
            type: 'areaspline',
            color: '#d9531e',
            fillOpacity: 0.2,
            yAxis: 0,
            zIndex: 3,
            visible: false,
            name: 'Last Year',
            data: [20, 2, 2, 7, 8, 5, 7, 3, 2, 2, 5, 5],
        }, {
            type: 'column',
            color: '#3fb4ed',
            fillOpacity: 0.2,
            yAxis: 1,
            zIndex: 1,
            visible: false,
            name: 'Revenue',
            data: [1, 1, 1, 1, 1, 1, 1, 1, 3, 4, 4, 2]
        }]

    });
});

I have tried every possible solutions out there. 我已经尝试了所有可能的解决方案。 Went through API docs and searched every forum. 通过API文档并搜索每个论坛。 Any help would be much appriciated. 任何帮助都会很有帮助。

You can set for xAxis: 您可以为xAxis设置:

    xAxis: {
        labels: {
            enabled: true,
            formatter: function () {
                return categories[this.value];
            }
        },
        tickInterval: 1,
        minPadding: 0,
        maxPadding: 0,
        min: 0.5,                     // remove padding
        max: categories.length - 1.5, // remove padding
        startOnTick: false,           // allow to start not from tick
        endOnTick: false              // allow to end not at tick
    },

Example: http://jsfiddle.net/p2EYM/24/ - turn on Revenue - you will see that first and last column will be cut off. 示例: http//jsfiddle.net/p2EYM/24/ - 打开收入 - 您将看到第一列和最后一列将被切断。

The reason it is doing this is because, even though the series is hidden on load, you have a column series that needs the width to display. 这样做的原因是,即使系列在加载时隐藏,您也有一个需要显示宽度的列系列。 If you just show series "Revenue" you can see it is using that empty space that was there before. 如果您只显示系列“收入”,您可以看到它正在使用之前存在的空白空间。 You could also play with tickPixelInterval - but for that you need to not use a categorized xAxis. 你也可以使用tickPixelInterval - 但为此你不需要使用分类的xAxis。

See this example . 看这个例子 I also set showEmpty to false for both yAxis elements. 我还为两个yAxis元素将showEmpty设置为false。

If you change the last of series from 如果您更改系列的最后一个

    type: 'column',

to

    type: 'areaspline',

there will be no gaps on left and right side. 左右两侧没有间隙。 Do you need type column ? 你需要型号column吗?

Solution for your problem is answered here Highcharts Remove Space across the x-Axis by user Dusty. 此处回答了您的问题的解决方案Highcharts用户Dusty 在x轴上删除空间 You have to setup for x-axis: 您必须为x轴设置:

    min: 0.5,
    max: 10.5,

Note: if you turn your column type series to visible: true half of the first and the last column will be cut-off. 注意:如果您将column类型系列变为visible: true将切断第一列和最后一列的一半。

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

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