日期 x 轴上的 Highcharter 注释不起作用 - R
Highcharter annotation on date x-axis not working - R
我正在尝试为我的 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!')))
这是图表,
可以看到左上角的注释为[object][object]。
编辑:尝试了答案,但没有用。
按照示例https://www.highcharts.com/demo/annotations, and reading this greate tutorial 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)
)
)
)
)
可悲的是,highchartsJS 需要大量嵌套列表,因此我们需要在 highcharter 中添加注释(到目前为止)
我正在尝试为我的 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!')))
这是图表,
可以看到左上角的注释为[object][object]。
编辑:尝试了答案,但没有用。
按照示例https://www.highcharts.com/demo/annotations, and reading this greate tutorial 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)
)
)
)
)
可悲的是,highchartsJS 需要大量嵌套列表,因此我们需要在 highcharter 中添加注释(到目前为止)