2

All, trying to build a stacked column chart using the highchart() function combined with the add_series-list. Using: Highcharter stacked column groupings not using hchart()

Most of the way there but when I run through the highcharter code I end up with a plot that is: Correctly themed, Correctly titled and the OrderTypes appear to be accounted for. However, I end with a No Data to display. have tried to simplify and dropped the second list. Here is what I have:

orderTypeBar <- monthSummary %>%
  group_by(OrderType) %>%
  do(monthSummary = list_parse2(.[, c('monthGroup', 'Total')])) %>%
  rename(name = OrderType) %>%
  mutate(OrderType = 'column') %>%
  list_parse()

highchart() %>%
  hc_add_theme(hc_theme_ffx()) %>%
  hc_title(text = "Revenue By Order Type") %>%
  hc_add_series_list(orderTypeBar) %>%
  hc_xAxis(categories = monthSummary$monthGroup) %>%
  hc_plotOptions(series=list(stacking='normal'))

The Summary table is built with the following dplyr transform.

monthSummary <- data %>%
  group_by(monthGroup, OrderType) %>%
  summarise(CustomerNumber = n()
            , SalesFulfilled = sum(Fulfilled)
            , SalesFreight = sum(Freight)
            , SalesTax = sum(Tax)
            , ServiceLabor = sum(LaborAmount)
            , ServiceMaterials = sum(MaterialCost)
            , Total = sum(Total)) %>%
  ungroup()

Plot result: Plot - Empty Data

Code for producing a subset of data:

test <- tibble::tribble(
    ~monthGroup,     ~OrderType, ~TransActionCount, ~SalesFulfilled, ~SalesFreight, ~SalesTax, ~ServiceLabor, ~ServiceMaterials,   ~Total,
    "2017-01",       "Credit",                4L,            -189,             0,      -3.6,             0,                 0,   -192.6,
    "2017-01",    "Equipment",                9L,           12286,             0,    250.66,             0,                 0, 12536.66,
    "2017-01",   "Networking",                2L,             9.9,             0,         0,             0,                 0,      9.9,
    "2017-01",   "Part Order",                2L,             658,             0,     39.48,             0,                 0,   697.48,
    "2017-01", "Service Call",              190L,               0,             0,         0,       9523.62,            2287.9, 12269.38,
    "2017-01",       "Supply",               76L,        26682.18,             5,   1274.05,             0,                 0, 24639.73
)
Tung
  • 26,371
  • 7
  • 91
  • 115
Jabberwockey
  • 349
  • 1
  • 6
  • 18
  • Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Dec 04 '18 at 05:28
  • 1
    Yes definitely. Apologies on not adding that originally. I have added a snippet that will produce a subset of the monthSummary data frame. – Jabberwockey Dec 04 '18 at 05:54

1 Answers1

2

You need type = 'column' and hc_xAxis(categories = test$monthGroup)

library(tidyverse)
library(highcharter)

test <- tibble::tribble(
  ~monthGroup,     ~OrderType, ~TransActionCount, ~SalesFulfilled, ~SalesFreight, ~SalesTax, ~ServiceLabor, ~ServiceMaterials,   ~Total,
  "2017-01",       "Credit",                4L,            -189,             0,      -3.6,             0,                 0,   -192.6,
  "2017-01",    "Equipment",                9L,           12286,             0,    250.66,             0,                 0, 12536.66,
  "2017-01",   "Networking",                2L,             9.9,             0,         0,             0,                 0,      9.9,
  "2017-01",   "Part Order",                2L,             658,             0,     39.48,             0,                 0,   697.48,
  "2017-01", "Service Call",              190L,               0,             0,         0,       9523.62,            2287.9, 12269.38,
  "2017-01",       "Supply",               76L,        26682.18,             5,   1274.05,             0,                 0, 24639.73
)

orderTypeBar <- test %>%
  group_by(OrderType) %>%
  do(data = list_parse2(.[, c('monthGroup', 'Total')])) %>%
  rename(name = OrderType) %>% 
  mutate(type = 'column') %>% 
  list_parse()

highchart() %>%
  hc_xAxis(categories = test$monthGroup) %>%
  hc_add_series_list(orderTypeBar) %>% 
  hc_add_theme(hc_theme_ffx()) %>%
  hc_title(text = "Revenue By Order Type") %>%
  hc_plotOptions(column = list(
    dataLabels = list(enabled = TRUE),
    stacking = "normal",
    enableMouseTracking = TRUE))

Tung
  • 26,371
  • 7
  • 91
  • 115
  • 1
    Tung, worked like a charm. Thought the column was being set by the orderTypeBar component, will need to dig into that. Much appreciated! – Jabberwockey Dec 06 '18 at 05:20