简体   繁体   English

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

[英]R Highcharter: On x-axis, Date is not showing correctly when dataframe has only one result

I'm building a shiny app that displays actual vs planned expenditure on a monthly basis.我正在构建一个闪亮的应用程序,每月显示实际支出与计划支出。 I've created controls that allow the user to select a specific project.我创建了允许用户选择特定项目的控件。 But in some projects, there are only planned expenditure for a single month is there.但是在一些项目中,只有一个月的计划支出是有的。 For those projects, the Date is not coming properly on the X-Axis.对于这些项目,日期在 X 轴上不正确。

计划支出与实际支出

He is the code that I've written:他是我写的代码:

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)
})

Finally found the solution on this link: https://github.com/jbkunst/highcharter/issues/395终于在这个链接上找到了解决方案: https : //github.com/jbkunst/highcharter/issues/395

Just need to make this change:只需要进行此更改:

hc_xAxis(categories = as.list(planned_vs_actual()$documentDate), title = list(text = "<b>Date</b>"), type = "datetime")

Put the date in as.list() function to show it properly on x-axis.日期放在as.list()函数中以在 x 轴上正确显示它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM