gpt4 book ai didi

javascript - 日期 x 轴上的 Highcharter 注释不起作用 - R

转载 作者:行者123 更新时间:2023-11-29 23:29:16 24 4
gpt4 key购买 nike

我正在尝试为我的 highcharter 图表添加注释,不确定为什么它不起作用,而是显示 [object][object]。

这是我的数据,

structure(list(variable = structure(c(15522, 15553, 15584, 15614, 
15645, 15675, 15706, 15737, 15765, 15796), class = "Date"), value = c(417376,
423563, 430290, 455643, 451542, 422419, 429472, 451694, 454900,
456844)), row.names = c(NA, 10L), .Names = c("variable", "value"
), class = "data.frame")

代码,我试图只为图中的最后一个值添加注释,可能在一个矩形框中。

currmonth <- max(pricedata$variable)
pricedata$value <- round(pricedata$value)
highchart(type = "chart") %>%
hc_chart(backgroundColor = "white",zoomType = 'x') %>%
hc_add_series_times_values(pricedata$variable, pricedata$value, name = "Price") %>%
hc_annotations(list(xValue = currmonth, title = list(text = 'Annotated chart!')))

这是图表,

enter image description here

你可以看到左上角的注解是[object][object]。

编辑:尝试了答案,但没有用。

enter image description here

enter image description here

enter image description here

最佳答案

下面的例子https://www.highcharts.com/demo/annotations ,并阅读这个很棒的教程 https://dantonnoriega.github.io/ultinomics.org/post/2017-04-05-highcharter-explainer.html这是可能的。

首先,最好使用hchart函数创建图表。

library(tidyverse) # for pull and last
library(highcharter)

currmonth <- max(data$variable)
lastvalue <- data %>% pull(value) %>% last()

hc <- hchart(data, "line", hcaes(variable, value))

然后添加复制给定链接的注释:

hc %>% 
hc_annotations(
list(
labelOptions = list(y = 50, x = 0),
labels = list(
list(
point = list(
x = highcharter::datetime_to_timestamp(currmonth),
y = lastvalue,
xAxis = 0,
yAxis = 0
),
text = scales::dollar(lastvalue)
)
)
)
)

enter image description here

遗憾的是 highchartsJS 需要很多嵌套列表,所以这就是我们需要做的在 highcharter 中添加注释(到现在为止)

关于javascript - 日期 x 轴上的 Highcharter 注释不起作用 - R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47935128/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com