【发布时间】:2018-06-04 07:50:26
【问题描述】:
我正在使用 Highcharter 的极坐标图,想知道它是否能够根据标准更改颜色。我正在使用图表来查看预算与支出。当支出 预算时,我希望该栏为红色。这可能吗?
对于代码中的示例:“物流”和“IT 与电信”支出为绿色,所有其他支出类别为红色。
答案必须是动态的,因为超出或低于计划的内容会不断变化。
以下是代码的简化版本。
library (shiny)
library (highcharter)
hc <- highchart() %>%
hc_chart(polar = TRUE) %>%
hc_title(text = "Budget vs Spending") %>%
hc_xAxis(categories = c("Energy", "Facilties", "IT & Telecom",
"Logistics", "Office Products", "Plant Consumables",
"Temp Labor", "Travel", "Other"),
tickmarkPlacement = "on",
lineWidth = 0) %>%
hc_yAxis(gridLineInterpolation = "polygon",
lineWidth = 0,
min = 0) %>%
hc_series(
list(
name = "Spend",
data = c(50000, 39000, 42000, 31000, 26000, 14000, 26000, 26000, 26000),
pointPlacement = "on",
type = "column"
),
list(
name = "Budget",
data = c(43000, 19000, 60000, 35000, 17000, 10000,10000,10000,10000),
pointPlacement = "on",
type = "line"
)
)
hc
【问题讨论】:
-
我对 R 了解不多,但在 Highcharts JS 中,我会将负责更新的代码放在
chart.events.render属性中:jsfiddle.net/kkulig/88mb6mq8 我使用redrawEnabled标志来防止无限递归循环是由于在此事件中重绘图表引起的(render自己调用redraw事件)。
标签: r highcharts shiny r-highcharter