jbkunst / highcharter

R wrapper for highcharts
http://jkunst.com/highcharter/
Other
719 stars 148 forks source link

column chart, hc_xAxis with only one value #395

Open steve-liang opened 6 years ago

steve-liang commented 6 years ago

Hi Joshua,

Thanks for such a great package. It's one of the best plotting packages in the open source realm. Since then I've been studying highcharts API and I am really glad I stumbled upon this.

I wonder if you ever get asked this questions. I tried to search through open/closed issues here and don't find anything related.

So in a column chart like this in your example, everything works as expected. highchart() %>% hc_chart(type = "column") %>% hc_title(text = "A highcharter chart") %>% hc_xAxis(categories = 2012:2016) %>% hc_add_series(data = c(3900, 4200, 5700, 8500, 11900), name = "Downloads")

But when the category has only 1 value. Such as, highchart() %>% hc_chart(type = "column") %>% hc_title(text = "A highcharter chart") %>% hc_xAxis(categories = 2012) %>% # or even hc_xAxis(categories = c(2012)) %>%
hc_add_series(data = c(3900), name = "Downloads")

The xaxis label as well as hover info don't populate 2012 but instead a 0

I played around and the only time I get it work with 1 category value is to make it a list hc_xAxis(categories = list(2012)). However it won't work if it's a vector (array) hc_xAxis(categories = list(2012, 2013, 2014))

Hope it's not a difficult one to troubleshoot. Steve

steve-liang commented 6 years ago

I got a workaround with use of as.list().

highchart() %>% hc_chart(type = "column") %>% hc_title(text = "A highcharter chart") %>% hc_xAxis(categories = as.list(2012)) %>% # multiple values will work too as.list(2012:2016) hc_add_series(data = c(3900), name = "Downloads")

jbkunst commented 6 years ago

Hi @steve-liang !

Yes, that is the solution, similar to #119 #118 #65 #71.

I will try to make a fix to avoid that