坐标空间的原点



我用以下代码(JSBin)绘制了一个坐标空间。我不明白的是,为什么(-1.7,0)不在原点?现在看来原点代表(-1.675,-0.25),这不是我想要的。

<!DOCTYPE html>
<html>
<body>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="height:400px;margin:1.5em 1em;"></div>
<script>
var chart = new Highcharts.Chart({
chart: {
renderTo:'container',
type:'area'
},
credits: false,
legend: false,
title: { text:"" },
tooltip: {},
plotOptions: {
series: {
color:'rgba(156,156,156,.9)',
fillColor:'#ffffff',
lineWidth:1,
marker: {
enabled:false,
states: {
hover: {
enabled:false
}
}
}
}
},
xAxis: {
tickmarkPlacement:'on',
categories:[-1.7, -1.65, -1.6, -1.55, -1.5, -1.45, -1.4, -1.35, -1.3]
},
yAxis: {
title: { text: "x 10000", rotation: 0, y: 0, x:10, margin: -40, align: 'high'},
tickLength: 10,
tickWidth: 1,
lineWidth: 1,
tickmarkPlacement:'on',
gridLineColor:'#ffffff',
categories:[0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]
},
series:[{  
data:[[1,1],[1,3],[2,3],[2,1],[1,1]]
}]      
});
</script>
</body>
</html>

默认情况下,Highcharts会自动计算两个轴的极值。如果绘图上没有接近第一类的值(在您的示例中为1.7),则不用于设置最小极值。您可以使用minmax属性手动设置极值:

xAxis: {
tickmarkPlacement:'on',
categories:[-1.7, -1.65, -1.6, -1.55, -1.5, -1.45, -1.4, -1.35, -1.3],
min: 0,
max: 8
};

我认为在这种情况下使用类别是个坏主意。类别只是Highcharts如何格式化轴标签、数据标签、工具提示等的信息。类别的实际y轴值是它们在数组中的索引。因此,如果你创建这样的类别:

categories:[-1.7, -1.65, -1.6, -1.55, -1.5, -1.45, -1.4, -1.35, -1.3]

它们将被视为字符串,它们的数值是0、1、2、3…

这意味着,当您使用以下选项创建一个点时:{x: 0, y: 5},它将位于-1.7类别之上——这将变得非常令人困惑。

您应该使用以下选项(而不是categories数组)操作轴上的数值:

  • https://api.highcharts.com/highcharts/yAxis.min
  • https://api.highcharts.com/highcharts/yAxis.max
  • https://api.highcharts.com/highcharts/yAxis.tickInterval

最新更新