highcharter hc_axis not working correctly

…衆ロ難τιáo~ 提交于 2019-12-25 07:16:40

问题


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.


回答1:


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)



来源:https://stackoverflow.com/questions/40245096/highcharter-hc-axis-not-working-correctly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!