higchart显示刻度之间的空间不均匀



我有一个对数y轴的条形图。当我将y轴的min设置为接近0(例如0.1)时,刻度之间的间隔看起来相等。但是,当我根据要求将min设置为1000时,图表会改变其行为,并且刻度之间的空间变得不均匀。下面是一个例子https://jsfiddle.net/2vh9h2q3/。下面是代码本身:

  new Highcharts.Chart({
    "chart": {
      "zoomType": "xy",
      "renderTo": $('#container')[0],
      "type": 'bar'
    },
    "title": {
      "text": null
    },
    "subtitle": {
      "text": null
    },
    "credits": {
      "enabled": false
    },
    "exporting": {
      "enabled": false
    },
    "xAxis": {
      "categories": ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
      "title": {
        "text": null
      },
      "labels": {
        "align": "left",
        "x": 10
      },
      "lineWidth": 0,
      "tickWidth": 0
    },
    "yAxis": {
     "type": "logarithmic",
      "min": 1000,
      "labels": {
        "formatter": function() {
          return this.value % 1000 === 0 ? this.value / 1000 + "k" : this.value;
        }
      },
      "title": {
        "text": null
      }
    },
    "tooltip": {
      "useHTML": true,
      "shadow": false
    },
    "plotOptions": {
      "bar": {
        "dataLabels": {
          "enabled": false
        }
      },
      "series": {
        "cursor": "pointer"
      }
    },
    "series": [{
      "showInLegend": false,
      "data": [4951,1200,0,0,196484,179580,0,0,0,324,87014, 11]
    }]
  });

我想让最小值为1000,并在刻度之间获得偶数空格。我试着使用刻度选项,但没有成功

你可以使用tickPositions或tickPositioner,如果你想手动设置你的刻度的位置,使他们彼此之间的距离将是相同的:

"yAxis": {
  "type": "logarithmic",
  "min": 1000,
  "labels": {
    "formatter": function() {
      return this.value % 1000 === 0 ? this.value / 1000 + "k" : this.value;
    }
  },
  "tickPositions": [3, 4, 5, 6],
  "title": {
    "text": null
  }
},

在这种情况下,tickPositions数组中的数字是10的幂。例如,如果你的值等于3,你就会看到10^3 = 1000的值。

在这里你可以找到一个例子,它是如何工作的:https://jsfiddle.net/2vh9h2q3/1/

你需要记住,如果你想使用对数轴,你不应该使用小于或等于0的值

最新更新