[英]Custom Y-Axis in AnyChart
I have a requirement where the y-axis labels need to be the following: 1, 0.1, 0.01, 0.001, 0我有一个要求,其中 y 轴标签需要如下:1, 0.1, 0.01, 0.001, 0
Is there a way to achieve this custom y-axis in AnyChart?有没有办法在 AnyChart 中实现这个自定义 y 轴?
More or less possible.或多或少可能。 You can set the desired logarithmic scale with these settings:
您可以使用以下设置设置所需的对数刻度:
var logScale = anychart.scales.log();
logScale.minimum(0);
logScale.maximum(1);
// Get ticks
var ticks = logScale.ticks();
ticks.count(4);
// Minor ticks
var minorTicks = logScale.minorTicks();
minorTicks.count(3);
chart.yScale(logScale);
chart.yAxis({minorTicks: true, minorLabels: true});
However, as far as I know, it is not possible to jump from 0.001 to 0. This happens because internally the from 0.001 to 0 there is a big gap of numbers that we can't just skip while keeping the chart scale consistent.然而,据我所知,从 0.001 跳到 0 是不可能的。发生这种情况是因为从 0.001 到 0 在内部存在很大的数字差距,我们不能在保持图表比例一致的同时跳过这些数字。
Demo: https://playground.anychart.com/CnDenhWb/2演示: https : //playground.anychart.com/CnDenhWb/2
On the other hand if you really wish to show only [1, 0.1, 0.01, 0.001, 0]
, then you can add this code:另一方面,如果您真的只想显示
[1, 0.1, 0.01, 0.001, 0]
,那么您可以添加以下代码:
var ticksArray = [1, 0.1, 0.01, 0.001, 0];
chart.yScale().ticks().set(ticksArray);
This will hide other labels in between 0.001 and 0.这将隐藏 0.001 和 0 之间的其他标签。
Demo: https://playground.anychart.com/ABxQ3oBc/1演示: https : //playground.anychart.com/ABxQ3oBc/1
You can achieve that using the only logScale with applied manually required ticks.您可以使用唯一的 logScale 并手动应用所需的刻度来实现这一点。 For details, check the sample on the playground .
有关详细信息,请查看操场上的示例。 Below is the result:
结果如下:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.