首页 > 解决方案 > 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)
})

标签: rhighchartsr-highcharter

解决方案


终于在这个链接上找到了解决方案: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 轴上正确显示。


推荐阅读