如何增加highcharts中特定x刻度的tickLength

时间:2015-01-08 13:49:26

标签: highcharts

___________________________xAxis
| 10 ' 20 ' 30 | 40 ' 50 ' 60 | 70

如上所示,我想在10,40和70的开头增加x轴的tickLength。

我找到了Xaxis的tickLength属性,该属性可以有一个数值,但它会更新沿轴的所有刻度的长度。

有没有办法实现我的目标?

1 个答案:

答案 0 :(得分:2)

您可以添加其他x轴,该x轴将链接到主轴,并且将具有更长的选定刻度。在下面的示例中,使用tickPositions放置刻度线,但如果需要首先计算较长刻度线的位置,则可以使用tickPositioner。

JSFiddle:http://jsfiddle.net/qL550pmh/1/

/* Expect to increse the tick length infront of 2013, 2014 & 2015 */

//  |2013 |   |   |    | 2014 |    |    |    |2015
//  |                  |                     |

$(function () {

    var currentYear = '';
    var isMonthCombined = false;

    $('#container').highcharts({
        credits: {
            enabled: false
        },
        chart: {
            type: 'spline',
            style: {
                fontFamily: '"Open Sans", "Helvetica Neue", Helvetica, Arial',
                fontSize: 14
            },
            marginLeft: 78
        },
        title: {
            text: null
        },
        legend: {
            x: 40
        },
        xAxis: [{
            linkedTo: 1,
            categories: [],
            tickLength: 25,
            labels: {
                format: ' '
            },
            tickPositions: [3, 7]
        }, {
            gridLineColor: '#e0e0e0',
            gridLineWidth: 1,
            lineColor: '#e0e0e0',
            tickColor: '#e0e0e0',
            categories: ["Jan 2013 - Mar 2013",
                "Apr 2013 - Jun 2013",
                "Jul 2013 - Sep 2013",
                "Oct 2013 - Dec 2013",
                "Jan 2014 - Mar 2014",
                "Apr 2014 - Jun 2014",
                "Jul 2014 - Sep 2014",
                "Oct 2014 - Dec 2014",
                "Jan 2015"],
            labels: {
                formatter: function () {

                    var year = this.value.slice(-4);
                    if (currentYear != year) {
                        currentYear = year;
                        return currentYear;
                    }
                    return '';
                }
            }
        }],
        yAxis: {
            gridLineColor: '#e0e0e0',
            gridLineWidth: 1,
            lineColor: '#e0e0e0',
            title: {
                text: 'Views'
            },
            min: 0
        },
        plotOptions: {
            series: {
                allowPointSelect: true
            }
        },
        series: [{
            xAxis: 1,
            name: 'Views and Downloads',
            lineWidth: 6,
            color: '#f29400',
            marker: {
                symbol: 'circle',
                fillColor: '#FFFFFF',
                radius: 7,
                lineWidth: 5,
                lineColor: null
            },
            data: [21410,
            9413,
            3982,
            1000,
            0,
            5,
            176,
            104,
            3]
        }]
    });
});