【问题标题】:Series name with series color at the end of line series系列名称,行尾带有系列颜色系列
【发布时间】:2020-01-29 22:37:03
【问题描述】:

我想在系列末尾带有系列颜色的系列名称。我在这里寻找类似的输出 - Highcharts Line Chart, display series name at the end of line series

我可以在系列末尾包含系列名称,但无法将其显示为系列的颜色。这是我无法将它包含在 R 中的 highcharter 中的解决方案,因为它同时具有 单引号和双引号。 R 无法识别它。

 formatter: function() {
    return '<span style="color:'+this.series.color+'">'+this.series.name+'</span>';
  }

我的代码如下所示 -

highchart() %>% 
  hc_chart(type = "spline") %>% 
  hc_title(text = "Demo",
           align = "center",
           style = list(
             fontFamily = "Roboto",
             color = "#444",
             fontWeight = "bold"
           )) %>% 
  hc_xAxis(categories = iris$Species) %>% 
  hc_yAxis(labels = list(format = "{value}M")) %>% 
  hc_add_series(name   = "Sepal.Length", 
                data   = iris$Sepal.Length,
                marker = list(enabled= FALSE),
                color='red',
                lineWidth=4, 
                lineColor='red') %>% 
  hc_add_series(name   = "Petal.Length", 
                data   = iris$Petal.Length,
                marker = list(enabled= FALSE),
                type = "area", 
                color='#f6f3ef',
                lineWidth=3, 
                lineColor='#e4dcd2',
                dashStyle = "ShortDot") %>% 
  hc_plotOptions(
    series = list(
      dataLabels = list(
        enabled = TRUE,
        allowOverlap = TRUE,
        align = 'center',
        verticalAlign = 'bottom',
        style = list(fontSize = '14px', color = '#666'),
        formatter = JS("
              function() {
                  if (this.point.x == this.series.data.length - 1) {
                          return this.series.name;
                    }
                          return '';
                }")))) %>% 
  hc_tooltip(pointFormat="{point.series.name}:  €<b>{point.y:,.2f}M</b><br/>", shared= TRUE) %>% 
  hc_add_theme(anacap_theme(palettes = "lightbluegolden")) %>% 
  hc_exporting(enabled = TRUE)

【问题讨论】:

    标签: r highcharts r-highcharter


    【解决方案1】:

    既然你想在标记中保留双引号,你就不能这样转义双引号吗?

    formatter: function() {
      return '<span style=\"color:' + this.series.color + '\">' + this.series.name + '</span>';
    }
    

    【讨论】:

    • 每个点而不是每个系列似乎都有一个名字,所以我最终得到了很多很多名字
    • 我们如何才能只为R系列中的最后一点启用它?
    猜你喜欢
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    • 2012-09-01
    • 2018-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-17
    相关资源
    最近更新 更多