javascript - ApexCharts:热图工具提示格式化程序
问题描述
我正在使用 apexcharts 显示热图图表:
该系列以 Date 对象命名,这些对象在 y 轴上的格式如下:
yaxis: {
labels: {
formatter: function(value){
if(value instanceof Date){
return value.toLocaleDateString(undefined, {year: 'numeric', month: 'long'});
} else {
return value;
}
}
}
},
如何为工具提示获得相同的格式?它们改为显示日期对象的常规字符串表示,但我只想显示月份和年份(如在 y 轴上):
解决方案
将一个值传递给 options 数组,并为其中的 y 轴tooltip
的值设置一个格式化程序:title
tooltip: {
y: {
title: {
formatter: function(value){
if(value instanceof Date){
return value.toLocaleDateString(undefined, {year: 'numeric', month: 'long'});
} else {
try {
return new Date(value).toLocaleDateString(undefined, {year: 'numeric', month: 'long'});
} catch (e) {
return value;
}
}
}
}
}
}
确保检查传递给格式化程序的值的类型,并在必要时创建一个新的Date
对象。
推荐阅读
- xml - bash 从元素中提取多个属性值 - XML
- typescript - Typescript 控制流分析无法识别已知类型
- sql-server - 将 TIMESTAMP 列从 Oracle 移动到 SQL Server
- python - 如何使用 FirefoxProfile 或 FirefoxOptions 通过 Selenium 设置 Firefox 浏览器的窗口位置
- r - 如何将文本拆分为向量,其中每个条目对应于分配给每个唯一单词的索引值?
- javascript - 将 VueJS 与 HighCharts 一起使用时的性能问题
- oracle - Oracle APEX - 从 PL/SQL 访问字段
- r - 更改 r bookdown 中的章节颜色(pdf 输出)
- single-sign-on - CloudFoundry 快速入门问题。所有建议的修复都不起作用
- sql - 在 Range 分区中创建动态分区