r - R Highcharter:在 x 轴上,当数据框只有一个结果时,日期显示不正确
问题描述
我正在构建一个闪亮的应用程序,每月显示实际支出与计划支出。我创建了允许用户选择特定项目的控件。但是在一些项目中,只有一个月的计划支出。对于这些项目,X 轴上的日期不正确。
他是我写的代码:
renderHighchart({
highchart() %>%
hc_chart(type = "column") %>%
hc_xAxis(categories = planned_vs_actual()$documentDate, title = list(text = "<b>Date</b>"), type = "datetime") %>%
hc_add_series(name="Planned Expenditure",
data = planned_vs_actual()$PlannedExpenditure) %>%
hc_add_series(name="Actual Expenditure",
data = planned_vs_actual()$ActualExpenditure) %>%
hc_tooltip(borderWidth = 1.5,
pointFormat = paste('<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b><br/>')) %>%
hc_legend(enabled = TRUE) %>%
hc_title(text = "Planned vs Actual Expenditure (In Crores)") %>%
hc_subtitle(text = dataPeriod) %>%
hc_yAxis(title = list(text = "<b>Amount <br>(In Crores)</br></b>"))%>%
hc_add_theme(custom_theme)
})
解决方案
终于在这个链接上找到了解决方案:https ://github.com/jbkunst/highcharter/issues/395
只需要进行此更改:
hc_xAxis(categories = as.list(planned_vs_actual()$documentDate), title = list(text = "<b>Date</b>"), type = "datetime")
将日期放入as.list()
函数中以在 x 轴上正确显示。
推荐阅读
- reactjs - 即使初始化默认参数,TypeScript 也会抱怨 undefined
- python - python ctypes如何将字符串写入给定的缓冲区
- python - plotly sankey图定位
- android - Toast 无法识别上下文
- python - Python 从我的脚本运行单独的脚本
- python - 如何使用 np.sign 选择 2 个列表?
- angular-cli - 即使在角度 CLI 中创建了 CanActivate 防护,我仍在选择 CanDeactivate 选项
- ruby-on-rails - 您可以根据枚举属性值执行包含验证吗?
- python - 如何检查变量是否不等于字符串
- mysql - MySQL LOCATE 与 Bigquery 的等价物是什么?