如何强制Highcharts在xAxis上显示最后一个标签? [英] How to force Highcharts to show last label on xAxis?

查看:612
本文介绍了如何强制Highcharts在xAxis上显示最后一个标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来,在一个阶梯式xaxis正常的showLastLabel不起作用。就我而言,我只是每十年展示一次;但如果我想在任何情况下看到最新的一年,这是行不通的。 这是一个小提琴



<$ (


$
$ $ $ $ $ $ $ $ $ $ 容器,
类型:行
},
标题:
{
文本:化石燃料排放的二氧化碳 - 合计(CDIAC)
},
xAxis:
{
categories:['1961','1962','1963','1964','1965','1966','1967 , '1968年', '1969年', '1970年', '1971年', '1972年', '1973年', '1974年', '1975年', '1976年', '1977年', '1978年', '1979年', '1980年', '1981', '1982年', '1983', '1984年', '1985', '1986年', '1987', '1988年', '1989', '1990年', '1991','1992年, '1993年', '1994年', '1995年' '1996年', '1997年', '1998年', '1999年', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', 2008年','2009','2010'],
标签:
{
步骤:10
},
showLastLabel:true,
endOnTick:真
},
yAxis:
{
分钟:0
},
系列:
[{
data:[ 836290,884698,947139,970623,961804,953139,937905,986489,1053841,1027857,1039329,1043832,1088357,1065419,1005220,1094115,1055965,1082764,1121897,1104068,1052479,1019684,1015786,1037513,1048350, 1051961,1036999,1033773,1017926,1014450,930734,892705,878363,866267,864817,890342,862982,856064,823133,830657,854361,829449,834088,826572,807363,809521,784657,784000,732848,745994] ,
名称:德国
}]
});

});

感谢您提供任何提示!

解决方案

http://jsfiddle.net/grg4b6xk/5/ $

 图表:
{
renderTo:b $ b这是我能找到的最好的方式:容器,
类型:行,
事件:{
load:function(){
var ticks = $ .map(this.axes [0] .ticks,函数(t){return t;});
ticks [ticks.length-2] .render(0);





添加 load 事件处理程序。在这个事件处理程序中,使用轴x( axes [0] 是x和 axes [1] 是y) 。 ticks 是一个类似数组的对象,因此您需要将其映射到数组以通过索引访问它。该数组中的最后一项是位置-1的一个勾号,所以真正的最后一个勾号位于它之前的位置(因此它是长度 - 2 )。然后,调用 render 函数传递一个除以10的数字。我使用了0.因此,tick在最后一个位置上重新显示。


It seems that in a stepped xaxis the normal "showLastLabel" doesn't work. In my case, I am displaying every tenth year only; but if I want to see in any case the latest year, it doesn't work. Here is a fiddle.

$(function () {
var chart = new Highcharts.Chart(
            {
                chart:
                {
                    renderTo: "container",
                    type: "line"
                },
                title: 
                {
                    text: "Emissions of CO2 - from Fossil Fuels - Total (CDIAC)"
                },
                xAxis: 
                {
                    categories: ['1961','1962','1963','1964','1965','1966','1967','1968','1969','1970','1971','1972','1973','1974','1975','1976','1977','1978','1979','1980','1981','1982','1983','1984','1985','1986','1987','1988','1989','1990','1991','1992','1993','1994','1995','1996','1997','1998','1999','2000','2001','2002','2003','2004','2005','2006','2007','2008','2009','2010'], 
                    labels:
                    {
                        step: 10
                    },
                    showLastLabel: true,
                    endOnTick: true
                },
                yAxis: 
                {
                    min: 0
                },
                series: 
                [   {
                            data: [836290,884698,947139,970623,961804,953139,937905,986489,1053841,1027857,1039329,1043832,1088357,1065419,1005220,1094115,1055965,1082764,1121897,1104068,1052479,1019684,1015786,1037513,1048350,1051961,1036999,1033773,1017926,1014450,930734,892705,878363,866267,864817,890342,862982,856064,823133,830657,854361,829449,834088,826572,807363,809521,784657,784000,732848,745994],
                            name: "Germany"
                        }]
            });

});

Thanks for any hints!

解决方案

http://jsfiddle.net/grg4b6xk/5/ This is the best way I could find:

   chart:
   {
        renderTo: "container",
        type: "line",
        events:{
             load:function(){
                 var ticks = $.map(this.axes[0].ticks, function(t){return t;});
                   ticks[ticks.length-2].render(0);
            }
         }
    }

Add load event handler. In this event handler take ticks of axes x (axes[0] is x and axes[1] is y). ticks is an array-like object so you need to map it to an array to access it by index. The last item in that array is some tick with position -1 so the real last tick is in position before it (so it is length - 2). Then call the render function passing a number that divides by 10. I used 0. So the tick rerenders on the last position.

这篇关于如何强制Highcharts在xAxis上显示最后一个标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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