Highcharts 条形图缩放不起作用

Highcharts Bar Chart Zoom not working

如果您在 Highcharts 中使用条形图,缩放似乎无法正常工作。 您可以 select 该区域,并且还会出现 "Reset zoom" 按钮。然而,图表并未放大。

我添加到基本条形图示例中的唯一代码是缩放类型:

chart: {
    type: 'bar',
    zoomType: 'x'
},

完整示例:http://jsfiddle.net/966off9e/

这是错误还是功能? ;-)

我认为当您使用 categorized 轴时,这是 Highcharts 中的一个错误。但是解决方法是对该轴使用 min

xAxis: {
        categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'],
        title: {
            text: null
        },
        min: 0
}

这是DEMO

另一种可能是数据量大于cropThreshold变量。参见 this related post

您还可以看到此变量的 official docs。每种图形都有这个具有不同默认值的变量。你应该检查一下才能确定。

只需将 'minRange' 添加到 x 轴:http://jsfiddle.net/mushigh/axy8v9oa/

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto"></div>
$(function () {
    $('#container').highcharts({
        chart: {
            type: 'bar',
            zoomType: 'x'
        },
        title: {
            text: 'Historic World Population by Region'
        },
        subtitle: {
            text: 'Source: Wikipedia.org'
        },
        xAxis: {
            categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'],
            title: {
                text: null
            },
            minRange: 1,
        },
        yAxis: {
            title: {
                text: 'Population (millions)',
                align: 'high'
            },
            labels: {
                overflow: 'justify'
            }
        },
        tooltip: {
            valueSuffix: ' millions'
        },
        plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true
                }
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -40,
            y: 100,
            floating: true,
            borderWidth: 1,
            backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
            shadow: true
        },
        credits: {
            enabled: false
        },
        series: [{
            name: 'Year 1800',
            data: [107, 31, 635, 203, 2]
        }, {
            name: 'Year 1900',
            data: [133, 156, 947, 408, 6]
        }, {
            name: 'Year 2008',
            data: [973, 914, 4054, 732, 34]
        }]
    });
});