在具有对数轴的HighCharts图表中不考虑最小和最大轴值 [英] min and max axis value not respected in HighCharts chart with a logarithmic axis

查看:147
本文介绍了在具有对数轴的HighCharts图表中不考虑最小和最大轴值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个堆积的柱状图,其中有一个对数缩放的y轴(JSFiddle 此处,改编从基本的演示图表)

I have the a stacked column chart with a logarithmic scaled y axis (JSFiddle here, adapted from a basic demo chart)

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'column'
        },
        yAxis: {
                type:'logarithmic',
            min: 0.3, // I WANT THE Y-AXIS TO START AT 0.3
            min: 25, // I WANT THE Y-AXIS TO END AT 25
            endOfTick:false,
            maxPadding:0,
                    tickInterval:0.1,
        },
        plotOptions: {
            column: {
                stacking: 'normal',
            }
        },
        series: [{
            data: [5, 3, 4, 7, 2]
        }, {
            data: [2, 2, 3, 2, 1]
        }, {
            data: [3, 4, 4, 2, 5]
        }]
    });
});

我在Stackoverflow 页面设置确切的最小和最大y轴值,但没有成功。
我能做些什么来强制y轴图表开始和结束于我想要的值?

I worked on all the options suggested on this Stackoverflow page to set the exact minimum and maximum y-axis values but without success. What can I do to force the y-axis chart to start and end at the values I want?

推荐答案

正如在你发现的问题中,使用塞巴斯蒂安的答案, tickPositioner 。事实上,将 startOnTick endOnTick 设置为false时,极值是正确的,只是标签不会呈现。在这种情况下,使用 tickPositioner ,例如:

As in the question you found, use Sebastian's answer, with tickPositioner. In fact, extremes are proper when setting startOnTick and endOnTick to false, just labels are not rendered. In that case use tickPositioner, for example:

  tickPositioner: function(min, max) {
    var ticks = this.tickPositions;

    ticks = $(ticks).filter(function(i, tick) {
      return tick > min && tick < max;
    });

    ticks.slice(0, 0, min);
    ticks.push(max);

    return ticks;

  }

现场演示: http://jsfiddle.net/99w72efv/5/

这篇关于在具有对数轴的HighCharts图表中不考虑最小和最大轴值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆