highcharts - HighChart - 在悬停时显示 null 的工具提示
问题描述
我的 HighCharts 折线图中有一个空值。我设置connectNulls: true
为当数据为空时线路不会断开。但是我不能将鼠标悬停在那个空值上。当我尝试时,它会自动跳转到最近的非零点。
小提琴:https ://jsfiddle.net/wmoxLy4r/2/
我想做的是:
1/ 允许悬停在空值上
2/ 当悬停在空值上时,我想在左边显示最接近的非空值的值。在这种情况下,它会显示129.2
.
我考虑过用最接近的非空值来估算空值,但由于 2 个周期具有相同的值,因此该部分的图将是平坦的。我希望情节看起来像现在一样。感谢任何帮助
解决方案
您可以预处理数据并计算中间点。零点没有标记,也无法为其显示工具提示。
const data = [...];
const processedData = data.map((dataEl, index) => {
if (!dataEl) {
return {
y: (data[index - 1] + data[index + 1]) / 2,
isCalculatedValue: true,
marker: {
fillColor: 'red',
radius: 1
}
}
}
return dataEl;
});
通过使用tooltip.formatter
函数,您可以在工具提示中显示上一个点值。
tooltip: {
formatter: function(tooltip) {
let point = this.point;
if (point.isCalculatedValue) {
point = this.series.points[point.index - 1];
}
return "<span style='font-size: 10px'>" + point.category + "</span><br/>" +
"<span style='color:" + point.series.color +
"'>●</span> Line series: <b>" + point.y + "</b><br/>";
}
}
现场演示: https ://jsfiddle.net/BlackLabel/nrmgaw6q/
API 参考: https ://api.highcharts.com/highcharts/tooltip.formatter
推荐阅读
- proguard - 如何修复 Proguard 删除 java.security 代码
- sql-server - 创建非聚集索引超时
- python - 熊猫列名中的Python编码问题\ufeff
- sql - 如何请求不区分大小写的对象
- javascript - 基于语言的特定 cookie 作为子域
- reactjs - 如何使用 jasmine 和酶测试 React useEffect hooks
- php - 基于第一个字符的条件正则表达式长度
- python - 读取 RAW 图像更大
- reactjs - Mapbox GL、Deck GL 和 React Map GL 之间的底层架构是什么?
- matplotlib - seaborn.swarmplot 符号比例的问题:零没有扩展