我想调整 yAxis 类别的位置。具体来说,我希望第一个类别(“低”)从 xAxis 线开始,之前没有任何填充或空格。
Highcharts.chart("container", {
chart: {
type: "line",
},
title: {
text: "Monthly Data",
},
xAxis: {},
yAxis: [{
opposite: true,
categories: ["Low", "Meduim", "High"],
title: {
text: "Severity",
},
},
{
title: {
text: "Measurment",
},
},
],
series: [{
yAxis: 0,
name: "Severity",
data: [0, 1, 0, 1, 0, 0, 0, 1, 1],
},
{
yAxis: 1,
name: "Measurment",
data: [0, 5, 20, 5, 2, 5, 1],
},
],
tooltip: {
shared: true,
valueSuffix: "",
},
})
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="height: 300px; margin-top: 1em"></div>
<button id="button">Export chart</button>
我建议不要使用分类轴,而是使用数字轴并使用
labels.formatter()
函数回调分配适当的类别。
yAxis: [{
tickPositions: [0, 1, 2],
labels: {
formatter: function () {
const categories = ["Low", "Medium", "High"];
return categories[this.value];
}
}
}]
演示: https://jsfiddle.net/BlackLabel/58xwtcaj/
API: https://api.highcharts.com/highcharts/yAxis.labels.formatter