首页 文章

Highcharts Bar延伸过MaxValue

提问于
浏览
1

我想在Highcharts中制作一个简单的条形图 . 但是,我希望最大值小于系列中的实际最大值,并提供正在发生的视觉线索 .

如果您引用了highcharts演示:http://www.highcharts.com/demo/bar-basic

我希望刻度以4,000结束,即使最长的条延伸到4054.这部分很简单,只需设置Max即可 .

但是,我想要一些视觉指示器让用户知道酒吧超出了最大值 . 这适用于系列中的最高值如此之高的情况,这使得很难看到图中的其他值相对于彼此 . 我们基本上不需要关注异常值,但需要知道它位于轴外 .

通过思考,我可以将ticks设置为小于最大值,并以tickInterval false结束 . 还有其他选择吗?

1 回答

  • 1

    那么这个信息应该显示在哪里?

    我准备了一个简单的例子,它在工具提示和图表下方的报告div中标记了这些信息 .

    http://jsfiddle.net/sbochan/8sKcs/

    $(function () {
    var chart;
    $(document).ready(function() {
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                type: 'bar'
            },
            title: {
                text: 'Historic World Population by Region'
            },
            subtitle: {
                text: 'Source: Wikipedia.org'
            },
            xAxis: {
                categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'],
                title: {
                    text: null
                }
            },
            yAxis: {
                min: 0,
                max:4000,
                title: {
                    text: 'Population (millions)',
                    align: 'high'
                },
                labels: {
                    overflow: 'justify'
                }
            },
            tooltip: {
                formatter: function() {
                    if(this.y > (this.series.chart.yAxis[0].max))
                        return this.series.name +': '+ this.y + ' max is smaller: '+this.series.chart.yAxis[0].max ;
                    else
                        return this.series.name +': '+ this.y;
                }
            },
            plotOptions: {
                bar: {
                    dataLabels: {
                        enabled: true
                    }
                }
            },
            credits: {
                enabled: false
            },
            series: [{
                name: 'Year 2008',
                data: [973, 914, 4054, 732, 34]
            }]
        },function(chart){
    
            var max = chart.yAxis[0].max,
                content = '<h2>Points</h2>
    '; $.each(chart.series,function(i,serie){ $.each(serie.data,function(j,data){ if(data.y > max) content += 'Point: '+data.y+' is bigger than max: '+max; }); }); $('#report').html(content); }); });

    });

    编辑:

    你也可以添加

    data.graphic.attr({
                       fill:'yellow'
                     });
    

    改变酒吧的颜色 .

相关问题