Javascript 如何隐藏高图 x 轴数据值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7928906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 04:05:57  来源:igfitidea点击:

how to hide highchart x - axis data values

javascriptjquerychartshighchartsbar-chart

提问by Nurul Asad

I am drawing a bar chart using highchart.js

我正在使用绘制条形图 highchart.js

I do not want to show the x - axis data values.

我不想显示 x 轴数据值。

Can any one tell me which option does it?
full config:

谁能告诉我是哪个选项?
完整配置:

var chart = new Highcharts.Chart({
                chart: {
                    renderTo: container,
                    defaultSeriesType: 'bar'
                },
                title: {
                    text: null
                },
                subtitle: {
                    text: null
                },
                xAxis: {
                    categories: [''],
                    title: {
                        text: null
                    },
                    labels: {enabled:true,y : 20, rotation: -45, align: 'right' }

                },
                yAxis: {
                    min: 0,
                    gridLineWidth: 0,
                    title: {
                        text: '',
                        align: 'high'
                    }
                },
                tooltip: {
                    formatter: function () {
                        return '';
                    }
                },
                plotOptions: {
                    bar: {
                        dataLabels: {
                            enabled: true
                        },
                        pointWidth: 35,
                        color: '#D9CDC1'
                    }
                },
                legend: {
                    enabled: false
                },
                credits: {
                    enabled: false
                },
                series: [{
                    name: 'Year 1800',
                    data: [107]
                }]
            });

回答by Nick

In HighCharts, bar graphs use inverted axes, so the bottom axis is really the Y axis. (See also "column" graphs where the graphic is rotated 90 degrees, in which case the bottom axis is the X axis.)

在 HighCharts 中,条形图使用倒轴,因此底部轴实际上是 Y 轴。(另请参阅“柱状”图,其中图形旋转 90 度,在这种情况下,底部轴是 X 轴。)

You need to add the following to the yAxis config

您需要将以下内容添加到 yAxis 配置中

labels:
{
  enabled: false
}

See the following for full example: http://jsfiddle.net/k5yBj/433/

请参阅以下完整示例:http: //jsfiddle.net/k5yBj/433/

回答by Rahul Gupta

To hide labels on X-axis set the option labels: {enabled:false}like this:

要隐藏 X 轴上的标签,请设置如下选项labels: {enabled:false}

    .....
    ........
    ,
                    xAxis: {
                        categories: [''],
                        title: {
                            text: null
                        },
                        labels: {
                         enabled:false,//default is true
                         y : 20, rotation: -45, align: 'right' }

                    }


.....
....

To hide labels on y-axis set the option labels: {enabled:false}like this:

要隐藏 y 轴上的标签,请设置如下选项labels: {enabled:false}

.....
.......
,
                yAxis: {
                    min: 0,
                    gridLineWidth: 0,
                    title: {
                        text: '',
                        align: 'high'
                    },
                    labels:{
                        enabled:false//default is true
                    }
                },
.........
......

Refer the documentationfor futher understanding.

请参阅文档以进一步了解。

回答by RS3

The above popular answer hides the labels only, this left tick marks for me which I also wished to remove.

上面的流行答案仅隐藏了标签,这对我来说留下了刻度线,我也希望将其删除。

In that case this works well

在这种情况下,这很有效

    xAxis: {
            visible: false
        },

This is a simple solution to remove everything on the x/y axis for anyone interested. For more information please look here https://api.highcharts.com/highcharts/xAxis.visible

这是一个简单的解决方案,可以为任何感兴趣的人删除 x/y 轴上的所有内容。有关更多信息,请查看这里https://api.highcharts.com/highcharts/xAxis.visible

回答by 23 45

If hiding x data, then look at this https://jsfiddle.net/anrilafosel/3g4z5kc3/

如果隐藏 x 数据,那么看看这个 https://jsfiddle.net/anrilafosel/3g4z5kc3/

chart.xAxis[0].setCategories(newCategories);
for (i = 0; i < chart.series.length; i++) {
  var newData = [];
  for (j = 0; j < toggler_hc13.length; j++)
    if (toggler_hc13[j] === 1)
      newData.push(series_hc13[i].data[j]);
  chart.series[i].setData(newData);
}