【问题标题】:Highcharts hover xAxis Labels Unique ValueHighcharts 悬停 xAxis 标签唯一值
【发布时间】: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


【解决方案1】:

以下正则表达式应该可以满足您的需求。运行下面的 sn -p 来查看它的使用情况。

^[^_]*_([^<]*)<([^>]*)>[^[]*\[([^\]]*)]
  • ^在行首断言位置
  • [^_]* 匹配除_ 之外的任何内容任意次数
  • _ 按字面意思匹配
  • ([^&lt;]*) 将除&lt; 之外的任何字符任意次数捕获到捕获组1
  • &lt; 从字面上匹配这个
  • ([^&gt;]*) 将除&gt; 以外的任何字符任意次数捕获到捕获组2
  • &gt; 从字面上匹配这个
  • [^[]* 匹配除[ 之外的任何字符任意次数
  • \[ 匹配 [ 字面意思
  • ([^\]]*) 将除] 以外的任何字符任意次数捕获到捕获组3
  • ] 按字面意思匹配

const r = /^[^_]*_([^<]*)<([^>]*)>[^[]*\[([^\]]*)]/
const a = [
  'root<trace>.D_seasonality<trend>.D_poly[poly0]',
  'root<trace>.D_seasonality<trend>.D_poly[poly2]',
  'root<trace>.D_seasonality<seasonality>.F_spectral_entropy[spectral_entropy]'
]

a.forEach(function(s) {
  m = r.exec(s)
  console.log(`Hover: ${m[1]}_${m[2]}_${m[3]}`)
  console.log(`Label: ${m[3]}`)
})

【讨论】:

  • 非常感谢您的帮助!现在我只需要弄清楚如何专门从标签自定义 xaxis 值的鼠标悬停悬停。在 highcharts 中创建悬停或鼠标悬停是我完全无法理解的。谢谢参观。这让我迈出了第一步!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-16
  • 1970-01-01
  • 1970-01-01
  • 2014-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多