Highcharts 当y轴数据为空或0时,如何隐藏自动x轴?

Highcharts 当y轴数据为空或0时,如何隐藏自动x轴?,highcharts,Highcharts,我试图在堆叠列中y轴值为null o 0时隐藏x轴值,当使用其他字段进行筛选时,这应该是自动的 code如巴拉巴拉巴拉·莱尔德所述,您可以对数据进行预处理 Array.prototype.clean = function(deleteValue) { for (var i = 0; i < this.length; i++) { if (this[i] == deleteValue) { this.splice(i, 1) i--

我试图在堆叠列中y轴值为null o 0时隐藏x轴值,当使用其他字段进行筛选时,这应该是自动的


code

如巴拉巴拉巴拉·莱尔德所述,您可以对数据进行预处理

Array.prototype.clean = function(deleteValue) {
  for (var i = 0; i < this.length; i++) {
    if (this[i] == deleteValue) {         
      this.splice(i, 1)
      i--
    }
  }
  return this
}


const series = [{
  name: 'John',
  data: [4, 3, null, 7, 2]
}, {
  name: 'Jane',
  data: [5, 2, null, 2, 1]
}, {
  name: 'Joe',
  data: [1, 4, null, 2, 5]
}]

for (let i = 0; i < series.length; ++i) {
    // Remove nulls for data in all series
    series[i].data.clean()
}

const options = {
  chart: {
    type: 'column'
  },
  title: {
    text: 'Stacked column chart'
  },
  xAxis: {
    categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
  },
  yAxis: {
    min: 0,
    title: {
      text: 'Total fruit consumption'
    },
    stackLabels: {
      enabled: true,
      style: {
        fontWeight: 'bold',
        color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
      }
    }
  },
  legend: {
    align: 'right',
    x: -30,
    verticalAlign: 'top',
    y: 25,
    floating: true,
    backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
    borderColor: '#CCC',
    borderWidth: 1,
    shadow: false
  },
  tooltip: {
    headerFormat: '<b>{point.x}</b><br/>',
    pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
  },
  plotOptions: {
    column: {
      stacking: 'normal',
      dataLabels: {
        enabled: true,
        color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
      }
    }
  },
  series: series
}

const chart = Highcharts.chart('container', options)
Array.prototype.clean=函数(deleteValue){
for(var i=0;i”,
pointFormat:“{series.name}:{point.y}
总计:{point.stackTotal}” }, 打印选项:{ 专栏:{ 堆叠:“正常”, 数据标签:{ 启用:对, 颜色:(Highcharts.theme&&Highcharts.theme.dataLabelsColor)| |“白色” } } }, 系列:系列 } const chart=Highcharts.chart('container',选项)
实例:

欢迎来到StackOverflow!请稍微扩展您的问题:添加图表的小图片和必要的代码。这将帮助其他读者理解您的问题。使用类别,这不是内置功能。你必须对数据进行预处理。