简体   繁体   English

highcharter hc_axis 无法正常工作

[英]highcharter hc_axis not working correctly

Follow up on this post I am not able to get the x-axis labels in correct format using the code below.跟进这篇文章,我无法使用下面的代码以正确的格式获取 x 轴标签。

hchart(visits, "column", x = as.Date(VisitDate), y = freq, group = Clinic) %>% 
   hc_xAxis(categories = allDates$VisitDate, title = list(text = 'Deadline'), type = 'datetime', dateTimeLabelFormats = list(month = "%b", year = "%y")) %>%
   hc_plotOptions(column = list(
     dataLabels = list(enabled = FALSE),
     stacking = "normal",
     enableMouseTracking = TRUE)
   ) 

The resulting chart below has labels all messed up.下面的结果图表的标签都搞砸了。

在此处输入图片说明

Also is it possible to specify interval as in 1 month, 15 days etc.也可以指定间隔为 1 个月、15 天等。

在此处输入图片说明

hchart(visits, "column", hcaes(x = VisitDate, y = freq, group = Clinic)) %>% 
hc_xAxis(categories = allDates$VisitDate, title = list(text = 'Deadline'), type = 'datetime', dateTimeLabelFormats = list(month = "%b", year = "%y")) %>%
hc_plotOptions(column = list(
  dataLabels = list(enabled = FALSE),
  stacking = "normal",
  enableMouseTracking = TRUE)
) 

You need to add hcaes inside the hchart function.您需要在 hchart 函数中添加 hcaes。 There are some nice examples here Highcharter page这里有一些很好的例子Highcharter 页面

Also Highchart prefer dates as timestamp to work the way you want, please check this answer plotband.此外,Highchart 更喜欢将日期作为时间戳以您想要的方式工作,请查看此答案plotband。

I hope this help you.我希望这对你有帮助。 Have a nice day有一个美好的一天

edit1:编辑1:

With this code you can add the select range to date you want, however I think to this kind of data and chart it does not apply使用此代码,您可以将选择范围添加到您想要的日期,但是我认为它不适用于此类数据和图表

hchart(visits, "column", hcaes(x = VisitDate, y = freq, group = Clinic))%>% 
hc_xAxis(categories = allDates$VisitDate, title = list(text = 'Deadline'), 
type = 'datetime', dateTimeLabelFormats = list(month = "%b", year = "%y")) 
 %>%
hc_plotOptions(column = list(
dataLabels = list(enabled = FALSE),
stacking = "normal",
enableMouseTracking = TRUE)
 ) %>%
hc_rangeSelector(enabled = TRUE, buttons = list(
list(type = "all", text = "All"),
list(type = "month", count = 1, text = "1m"),
list(type = "day", count = 15, text = "15d"),
list(type = "day", count = 1, text = "1d")

), selected = 3)

前

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

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