Highcharts悬停xAxis标签的独特价值

时间:2018-02-28 17:38:00

标签: regex angular typescript highcharts hover

高等问题新手。

有一个为我的散点图解析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);
        }

      }
    }
  }

1 个答案:

答案 0 :(得分:0)

以下正则表达式应该可以满足您的需求。运行下面的代码段以查看其中的使用情况。

^[^_]*_([^<]*)<([^>]*)>[^[]*\[([^\]]*)]
  • ^在行首处断言位置
  • [^_]*匹配除_以外的任何内容
  • _按字面意思匹配
  • ([^<]*)<<之外的任何字符捕获到捕获组 1
  • ([^>]*)按字面意思匹配
  • >>[^[]*以外的任何字符捕获到捕获组 2
  • [按字面意思匹配
  • \[匹配除[以外的任何字符
  • ([^\]]*)按字面意思匹配]
  • ]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]}`) })除{{1}}以外的任何字符捕获到捕获组 3
  • {{1}}按字面意思匹配

{{1}}