【问题标题】:Highcharts : trouble with axis LabelHighcharts:轴标签的问题
【发布时间】:2014-11-13 17:55:23
【问题描述】:

我无法解释这种行为:
有时,我的图表会显示带有很多小数的轴的第一个或最后一个标签。

在我的图表选项中,yAxis 是这样的:

yAxis : [{
     alternateGridColor: "white",
     gridLineColor : "#E3E3E3",
     lineWidth: 2,
     tickLength : 5, 
     lineColor : '#A5A5A5',
     tickWidth : 2,
     tickLength : 5,
     tickColor : '#A5A5A5',
     labels : {
         style : {
             fontWeight : 'bold',
             fontSize: '10px'
         }, 
         x : -labelMargin
     },
     tickPixelInterval: 20  
},
//more axis
]

如何解决这个问题?任何帮助表示赞赏。

【问题讨论】:

    标签: javascript highcharts axis-labels


    【解决方案1】:

    您没有提到标签的值应该是什么,因此它使用可能是除法生成的浮点数的幼稚值。

    我建议您手动处理标签,如下所示:

        labels: {
            formatter: function () {
                return Math.floor(this.value)
            }
        }
    

    如您所见,我使用floor() 函数来删除小数。

    【讨论】:

    • 我添加了format: '{value:.2f}',正如预期的那样,它可以防止这种奇怪的行为再次出现。但是当轴显示“更大”的值(我的意思是 1、2、3、..)时,我不希望轴显示小数。有什么建议吗?
    • 我想你可以再做一次数学运算。例如,根据我的回答,它应该类似于:return (this.value - Math.floor(this.value)) 将小数分开。
    • @zbMax 使用任何检查值的条件都支持的label formatterHighcharts.numberFormat
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-26
    相关资源
    最近更新 更多