简体   繁体   中英

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.

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.

在此处输入图片说明

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. There are some nice examples here Highcharter page

Also Highchart prefer dates as timestamp to work the way you want, please check this answer plotband.

I hope this help you. Have a nice day

edit1:

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)

前

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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