简体   繁体   English

来自不同系列的 Highcharter 数据标签

[英]Highcharter dataLabels from different series

I have got the following code: It gives me a linechart with datalabels which correspond to the the values of the wt column.我有以下代码:它给了我一个带有数据标签的折线图,这些标签对应于wt列的值。 However I would like to display the values of the cyl series.但是我想显示cyl系列的值。 Something like this: return(this.series.cyl.y)像这样: return(this.series.cyl.y)

What I actually want to archieve with my "real" dataset is to calculate the difference of the previous value of the same series, which seems to be not possible because this.point.y does not return an array, but returns the actual values.我真正想用我的“真实”数据集进行this.point.y是计算同一系列的前一个值的差异,这似乎是不可能的,因为this.point.y不返回数组,而是返回实际值。 So the better solution would be to calculate a new series or column in R and use that column as dataLabel.所以更好的解决方案是在 R 中计算一个新的系列或列,并将该列用作 dataLabel。 Can someone help me?有人能帮我吗?

library(highchart)

highchart() %>%
    hc_add_series(type = "line", data = mtcars$wt, name = "cyl", dataLabels = list(
        enabled = TRUE,
        formatter = JS(
            'function(){
            return this.point.y
            //return(this.series.cyl.y)
        }'
        )
    ))

Try using format within hc_add_series :尝试在hc_add_series使用format

highchart() %>%
  hc_add_series(type = "line", data = mtcars, name = "cyl", hcaes(y = wt), 
                dataLabels = list(
                  enabled = TRUE,
                  format = "{point.cyl}"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM