highcharter hc_axis无法正常工作 [英] highcharter hc_axis not working correctly

查看:82
本文介绍了highcharter hc_axis无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关注此帖子我无法使用下面的代码以正确的格式获取x轴标签.

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.

还可以将间隔指定为1个月,15天等.

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

您需要在hchart函数内添加hcaes.这里有一些很好的示例高级"页面

You need to add hcaes inside the hchart function. There are some nice examples here Highcharter page

Highchart还希望日期作为时间戳以您想要的方式工作,请检查此答案

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)

这篇关于highcharter hc_axis无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆