R HighCharter - 无数据显示
R HighCharter - No Data To Display
全部,尝试使用 highchart() 函数结合 add_series-list 构建堆积柱形图。使用:
大部分都在那里,但是当我 运行 通过 highcharter 代码时,我最终得到了一个情节:
正确的主题、正确的标题和 OrderTypes 似乎都已说明。但是,我以无数据显示结束。试图简化并删除第二个列表。这是我拥有的:
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'))
摘要 table 是使用以下 dplyr 转换构建的。
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 - Empty 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
)
您需要 type = 'column'
和 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))
全部,尝试使用 highchart() 函数结合 add_series-list 构建堆积柱形图。使用:
大部分都在那里,但是当我 运行 通过 highcharter 代码时,我最终得到了一个情节: 正确的主题、正确的标题和 OrderTypes 似乎都已说明。但是,我以无数据显示结束。试图简化并删除第二个列表。这是我拥有的:
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'))
摘要 table 是使用以下 dplyr 转换构建的。
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 - Empty 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
)
您需要 type = 'column'
和 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))