echarts - 轴上的 maxLabel 格式与其他标签不同
问题描述
我希望专门为我的 y 轴上的上轴标签使用不同的格式。例如,如果我有一个百分比值轴,我希望仅在顶部轴标签上看到%符号,而其下方的其余标签仍保持格式为不带符号的数字。
到目前为止,我一直在使用该formatter
选项并创建了一个接收value
EChartsindex
文档的函数。下面的示例链接完成了我需要它做的事情,但它是针对轴的底部而不是顶部进行的。我需要一种方法来使用相同的逻辑,但选择轴上的最大索引。
链接到文档中的示例:
https ://echarts.apache.org/en/option.html#yAxis.axisLabel.formatter
文档中示例的代码:
这if (index === 0)
是我所指的逻辑
// Use callback function; function parameters are axis index
formatter: function (value, index) {
// Formatted to be month/day; display year only in the first label
var date = new Date(value);
var texts = [(date.getMonth() + 1), date.getDate()];
if (index === 0) {
texts.unshift(date.getYear());
}
return texts.join('/');
}
这是我尝试过的:
- 我试图使用该
index
参数来计算我的数据集中的最大索引 #,但由于该函数每个值调用一次并且仅包含该值的数据,因此无法弄清楚如何做到这一点。 - 我尝试传递
params
给该函数,因为这就是配置中的formatter
工作方式series
,但看起来这在axis
配置中是不可能的 - 一种(不吸引人的)替代方法是使用 y 轴
axisName
显示我想要附加到顶部标签的任何符号,并使用padding
. 这可能行不通,因为我还需要axisName
不时单独使用。
一个可能的提示这可能还不可能,但至少在
幕后我知道 ECharts 能够通过.showMaxLabel
axisLabel
有没有办法检查标签是否是formatter
轴函数中的最大标签?
解决方案
推荐阅读
- python - 如何for循环通过html元素uisng python selenium单击页面中的每个元素?
- javascript - 如何在 Visual Studio 代码中获取当前文件夹路径
- c++ - 如何将值从十进制存储到二进制,以便在 C++ 中将值保存在 6 个位置
- bash - 使用 bash 脚本获取源文件
- c++ - DFS 在 kefa 和 park 中提供 TLE (codeforces 560C)
- sql - 计算每个 PO 编号并告诉 PO 编号
- spring-boot - 通过CF中的环境变量配置Spring Eureka Client
- javascript - 如何通过 post 方法发送开关切换表单
- javascript - 在javascript中使用array.filter的正则表达式
- powershell - 在 Powershell EPS 文件中读取“用户级别”环境变量时出现问题