问题描述
我将 y 轴的可见性设为 false,因为我不想显示 y 轴,因此设为可见 false 但这里的问题是网格线也被删除了,需要保留在图表中。如何通过保留网格线来关闭 y 轴的可见性?
请在此处找到工作演示 => JSFiddle Demo 任何帮助将不胜感激。
这是我的代码部分:
Highcharts.chart('container',{
chart: {
type: 'scatter',zoomType: 'xy'
},title: {
text: 'Height Versus Weight of 507 Individuals by Gender'
},subtitle: {
text: 'Source: Subhojit'
},xAxis: {
title: {
enabled: true,text: 'Height (cm)'
},startOnTick: true,endOnTick: true,showLastLabel: true
},yAxis: {
title: {
text: 'Weight (kg)'
},visible: false
},legend: {
layout: 'vertical',align: 'left',verticalAlign: 'top',x: 100,y: 70,floating: true,backgroundColor: Highcharts.defaultOptions.chart.backgroundColor,borderWidth: 1
},plotOptions: {
scatter: {
marker: {
radius: 5,states: {
hover: {
enabled: true,lineColor: 'rgb(100,100,100)'
}
}
},states: {
hover: {
marker: {
enabled: false
}
}
},tooltip: {
headerFormat: '<b>{series.name}</b><br>',pointFormat: '{point.x} cm,{point.y} kg'
}
}
},series: [{
name: 'Female',color: 'rgba(223,83,.5)',data: <data>
}]
});
解决方法
根据这个 document 要隐藏标签,我们需要 labels
对象并且在该对象中需要传递 enabled: false
yAxis: {
title: {
text: 'Weight (kg)'
},labels: {
enabled: false
}
},
Highcharts Demo
,我找到了我一直在寻找的解决方案,如果有一天对任何人有帮助,我想与大家分享。
请在此处找到可行的解决方案 => JSFiddle Solution
下面是隐藏轴线和标签而不影响网格线的解决方案:
yAxis: {
title: {
text: 'Weight (kg)'
},labels: {
enabled: false
},lineColor: 'transparent'
},