问题描述
我正在尝试为我的高位图表添加注释,不确定为什么它不起作用,而是显示[object] [object].
I am trying to add annotation for my highcharter chart, not sure why it is not working, instead it is showing [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")
代码,我试图仅在图形中为最后一个值添加注释,可能在矩形框中.
Code, I am trying to add annotation only for last value in the graph, may be in a rectangle box.
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]的左上角.
You can see the annotation is in the top left corner as [object][object].
尝试了答案,但没有成功.
EDIT :Tried the answer and it didn't work.
推荐答案
以下示例 https://www.highcharts.com/demo/annotations ,并阅读本教程 https://dantonnoriega.github.io/ultinomics.org/post/2017-04-05-highcharter-explainer.html 是可能的.
Following the example https://www.highcharts.com/demo/annotations, and reading this greate tutorial https://dantonnoriega.github.io/ultinomics.org/post/2017-04-05-highcharter-explainer.html it's possible.
首先,最好使用hchart
函数创建图表.
First of all, it's better to create the chart using the hchart
function.
library(tidyverse) # for pull and last
library(highcharter)
currmonth <- max(data$variable)
lastvalue <- data %>% pull(value) %>% last()
hc <- hchart(data, "line", hcaes(variable, value))
然后添加注释以复制给定的链接:
Then add the annotation replicating the given links:
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中添加注释
Sadly highchartsJS need a lot of nested lists so that is what we need to do to add annotations in highcharter (by now)
这篇关于日期x轴上的Highcharter注释不起作用-R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!