Javascript 如何从Highcharts中删除未使用的xaxis值?

Javascript 如何从Highcharts中删除未使用的xaxis值?,javascript,highcharts,Javascript,Highcharts,我在7月4日和7月5日有一个这样的系列。但在这些点之间,会显示小时数。当X轴点没有相应的y轴值时,如何隐藏它们?在标签中。formatter函数您可以循环查看序列点以确定是否使用了当前值: xAxis: { ..., labels: { formatter: function() { var series = this.chart.series, s, p,


我在7月4日和7月5日有一个这样的系列。但在这些点之间,会显示小时数。当X轴点没有相应的y轴值时,如何隐藏它们?

标签中。formatter
函数您可以循环查看序列点以确定是否使用了当前值:

xAxis: {
    ...,
    labels: {
        formatter: function() {
            var series = this.chart.series,
                s,
                p,
                usedValue;

            for (s of series) {
                if (usedValue) {
                    break;
                }
                for (p of s.xData) {
                    if (p === this.pos) {
                        usedValue = true;
                        break;
                    }
                }
            }

            if (usedValue) {
                return Highcharts.dateFormat(this.dateTimeLabelFormat, this.pos)
            }

        }
    }
}

现场演示:

API参考:


Hi@Thunfsche,您想只删除未使用的
xAxis
标签还是同时删除带有网格线的记号?是的,我想删除未使用的指针,但您所说的
是什么意思?对不起,我是指xAxis标签
xAxis: {
    ...,
    labels: {
        formatter: function() {
            var series = this.chart.series,
                s,
                p,
                usedValue;

            for (s of series) {
                if (usedValue) {
                    break;
                }
                for (p of s.xData) {
                    if (p === this.pos) {
                        usedValue = true;
                        break;
                    }
                }
            }

            if (usedValue) {
                return Highcharts.dateFormat(this.dateTimeLabelFormat, this.pos)
            }

        }
    }
}