【发布时间】:2018-02-28 17:38:00
【问题描述】:
highcharts 问题的新手。
有一个函数可以为我的散点图解析 xAxis 的标签。工作正常,但值太长并被截断。这些需要在悬停时显示,而 xAxis 标签上显示的值应该是用括号括起来的字符串中的最后一个单词。示例和代码如下。有时间试图找到有关更改 Highchart 中 xAxis 的悬停结果的任何信息。
原始字符串: root.D_seasonality.D_poly[poly0]
在 parseLabels 函数之后。可见图表标签:“poly0”。
预期悬停:“seasonality_trend_poly0”(当前图表标签)。
已尝试将函数格式化或插入到 HighchartOptions/xAxis,但没有成功。
打字稿:
parseLabels(uniqueFeatures) {
this.labels = [];
for (let i = 0; i < uniqueFeatures.length; i++) {
let trimmedFeature = '';
let curFeature = uniqueFeatures[i];
let start = curFeature.search('>') + 4;
curFeature = curFeature.substr(start, curFeature.length);
let end = curFeature.search('<');
if (end === -1) {
end = curFeature.search('\\[');
}
let key = curFeature.substr(0, end);
trimmedFeature = trimmedFeature + key;
curFeature = curFeature.substr(end + 1, curFeature.length);
start = 0;
end = curFeature.search('>');
if (end === -1) {
if (trimmedFeature.length > 1) {
this.labels.push(trimmedFeature);
}
} else {
key = curFeature.substr(start, end);
trimmedFeature = trimmedFeature + '_' + key;
curFeature = curFeature.substr(end + 1, curFeature.length);
start = curFeature.search('\\[') + 1;
if (start !== -1) {
} else {
if (trimmedFeature.length > 4) {
this.labels.push(trimmedFeature);
}
}
end = curFeature.search('\\]');
key = curFeature.substr(start, (end - start));
trimmedFeature = trimmedFeature + '_' + key;
if (trimmedFeature.length > 4) {
this.labels.push(trimmedFeature);
}
}
}
}
【问题讨论】:
-
所以你想让
root.D_seasonality.D_poly[poly0]变成seasonality_trend_poly0?如果有,trend来自哪里? -
对不起,原来的字符串实际上是 "root
.D_seasonality .D_poly[poly0]" 它正在删除 部分。 -
实际上需要是“seasonality_trend_poly0”。然后另一个只捕获末尾括号中的部分,“poly0”。较长的字符串应该是悬停,较短的字符串应该是实际的 xAxis 标签。
-
您能否在您的问题中添加更多带有预期输出的样本?它有助于我们确保为您所有给定的样本提供一个有效的正则表达式(以防万一有一些特殊情况)
标签: regex angular typescript highcharts hover