【发布时间】:2019-08-05 16:06:49
【问题描述】:
我对 R 中的 highcharts 相当陌生,我正在尝试创建一个与此示例类似的子弹图:http://jsfiddle.net/jlbriggs/LdHYt/。我遇到的问题是在 R 中创建这个函数:
Highcharts.Renderer.prototype.symbols.line = function(x, y, width, height) {
return ['M',x ,y + width / 2,'L',x+height,y + width / 2];
};
我不确定将其添加到代码中的哪个位置。
我尝试在 hc_plotOptions 符号部分中包含此代码,但我没有任何运气。
这是我试过的代码:
library(dplyr)
library(highcharter)
actual <- c(5,10,3,15)
target <- c(6,7,5,12)
date <- as.Date(c('2012-02-01','2012-03-01','2012-04-01','2012-05-01'))
data <- data.frame(actual,target,date)
highchart(type = "stock") %>%
hc_add_series_list(
data %>%
group_by(
name = "actual",
type = "column",
yAxis = 0
) %>%
do( data = list_parse(data.frame(x = datetime_to_timestamp(.$date), y = .$actual)))
) %>%
hc_add_series_list(
data %>%
group_by(
name = "target",
type = "scatter",
yAxis = 0
) %>%
do( data = list_parse(data.frame(x = datetime_to_timestamp(.$date), y = .$target)))
) %>%
hc_plotOptions(
scatter = list(
marker = list(
# This is where I am inserting the Java Script code from the example
symbol = JS("function(x, y, width, height) {
return ['M',x ,y + width / 2,'L',x+height,y + width / 2];
};"),
#
lineWidth = 3,
radius = 8,
lineColor = "#000"
)
)
)
当我将此代码放入图表时,我的图表变为空白,并且没有显示任何内容。感谢您查看此内容。
【问题讨论】:
-
请添加您使用的数据和包,以便人们重现问题
-
对不起,迈克,我刚刚更新了帖子。
标签: r highcharts r-highcharter