【问题标题】:different tooltip than x-axis category text - highcharts与 x 轴类别文本不同的工具提示 - highcharts
【发布时间】:2015-09-18 16:20:42
【问题描述】:

我正在实施 highcharts api。 highcharts.com

我必须实现与实际的“x 轴/y 轴类别文本”不同的工具提示。 这是需要的,因为有时 x 轴类别文本太大,我想将其解析为 5-10 个字符,但我想在工具提示中显示全文。


小提琴示例:highchart sample fiddle

代码:

$(function () {

$('#container').highcharts({

    chart: {
    },

    xAxis: {
        categories: ['The weather is so good in January', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },

    tooltip: {
        valueDecimals: 2,
        valuePrefix: '$',
        valueSuffix: ' USD'
    },

    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }]

});
});

在上面的小提琴中:我想在轴文本中显示 "Jan" 以及工具提示中的“一月份的天气真好”。

提前致谢

【问题讨论】:

    标签: javascript highcharts


    【解决方案1】:

    我建议准备更短的解决方案,在 categoreis 数组中使用“短”类别名称,但在点对象中保留全名作为附加参数。

    tooltip: {
            formatter: function () {
                    console.log(this);
                var txt = 'y :' + this.y + ' short x: '+ this.key;
    
                if(this.point.fullCategory)
                    txt += this.point.fullCategory;
    
    
                return txt;
            }
    
        },
    

    查看示例:http://jsfiddle.net/4Nk87/1/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-20
      • 2015-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多