R Highcharter:在x轴上,当数据帧只有一个结果时,日期显示不正确

问题描述 投票:0回答:1

我正在构建一个闪亮的应用,该应用每月显示实际支出与计划支出。我创建了允许用户选择特定项目的控件。但是在某些项目中,只有一个月的计划支出。对于这些项目,“日期”在X轴上无法正确显示。

Planned vs Actual Expenditure

他是我编写的代码:

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)
})
r highcharts r-highcharter
1个回答
0
投票

最后在此链接上找到了解决方案: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轴上正确显示。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.