[英]R Highcharter: Formatting tooltip
我有一個“堆積條形圖”圖表,將其放在較寬的條形圖中,以查看它是否符合我的標准。 由於一個技巧(使用grouping = FALSE
,並且使每一列的總和是其前面各列的總和),我使該圖看起來像我想要的樣子。 現在的問題是, tooltip
顯示的數字不正確(正確)。
問題:有沒有一種方法可以格式化工具提示以顯示正確的數字(包括彩色點)或以其他方式創建圖形?
例如,圖片在tooltip
上顯示了錯誤的數字,我希望它顯示出來:
碼:
highchart() %>%
hc_add_series(TopPN2, "column", hcaes(x = Incoming.P.N, y = 21), name = "DIH Goal", color = "#ffffff", borderColor = "#C8C8C8", pointPadding = -0.1) %>%
hc_add_series(TopPN2, "column", hcaes(x = Incoming.P.N, y = round(HoldTime.Quote,1)), name = "Quote Hold Time", color = "#FF8888") %>%
hc_add_series(TopPN2, "column", hcaes(x = Incoming.P.N, y = round(Hold.Time.Other,1)), name = "Other Hold Time", color = "#E5A919") %>%
hc_add_series(TopPN2, "column", hcaes(x = Incoming.P.N, y = round(Shop.Time,1)), name = "Shop Time", color = "#51C1BC") %>%
hc_xAxis(type = "category") %>%
hc_yAxis(title = "hours", labels = list(format = "{value}hrs")) %>%
hc_tooltip(crosshairs = TRUE, shared = TRUE, headerFormat = "<b>{point.name}</b>", valueSuffix = "hrs") %>%
hc_plotOptions(column = list(grouping = FALSE))
數據:
> dput(TopPN2)
structure(list(Incoming.P.N = c("PN1", "PN2", "PN3", "PN4", "PN5",
"PN6", "PN7", "PN8", "PN9", "PN10"), HoldTime.Quote = structure(c(28.8846153846154,
32.548, 21.8717948717949, 57.4931506849315, 64.4074074074074,
40.0833333333333, 14, 29.680790960452, 36.6506024096386, 48.1111111111111
), class = "difftime", units = "days"), Hold.Time.Other = structure(c(22.7307692307692,
21.56, 16.7435897435897, 10.7123287671233, 47.1851851851852,
23.1666666666667, 6, 8.17231638418079, 25.1807228915663, 24.6666666666667
), class = "difftime", units = "days"), Shop.Time = c(3.40698998178506,
4.83416980342953, 3.33075767332046, 4.39068799583821, 5.35449386300647,
5.20028749401054, 3.43263196751569, 5.59119496855346, 4.27753861737149,
5.61884753901561), Quantity = c(17568, 9564, 9318, 7689, 7577,
6261, 5418, 5088, 3949, 3332)), .Names = c("Incoming.P.N", "HoldTime.Quote",
"Hold.Time.Other", "Shop.Time", "Quantity"), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
更新
順其自然地格式化tooltip
。 我創建了新的變量來表示正確的時間,但是我無法弄清楚如何在tooltip
輸入正確的色點。 在此處找到示例: 如何使用工具提示格式化程序並仍然顯示圖表顏色(如默認情況下一樣)? 展示了如何在JS中執行此操作,但我無法在R中弄清楚。我的問題是我不知道如何使用color span
之間的雙引號使它獲得正確的顏色。
更新數據:
> dput(TopPN2)
structure(list(Incoming.P.N = c("PN1", "PN2", "PN3", "PN4", "PN5",
"PN6", "PN7", "PN8", "PN9", "PN10"), Hold.Time.Quote = structure(c(28.8846153846154,
32.548, 21.8717948717949, 57.4931506849315, 64.4074074074074,
40.0833333333333, 14, 29.680790960452, 36.6506024096386, 48.1111111111111
), class = "difftime", units = "days"), Hold.Time.Other = structure(c(22.7307692307692,
21.56, 16.7435897435897, 10.7123287671233, 47.1851851851852,
23.1666666666667, 6, 8.17231638418079, 25.1807228915663, 24.6666666666667
), class = "difftime", units = "days"), Shop.Time = c(3.40528709494031,
4.83058282849384, 3.33075767332046, 4.38978424746556, 5.35178594965072,
5.19380460683082, 3.43263196751569, 5.59119496855346, 4.27753861737149,
5.61884753901561), Quantity = c(17590, 9574, 9318, 7694, 7587,
6295, 5418, 5088, 3949, 3332), HoldTimeQuoteTrue = structure(c(6.2,
11, 5.1, 46.8, 17.2, 16.9, 8, 21.5, 11.5, 23.4), class = "difftime", units = "days"),
HoldTimeOtherTrue = structure(c(18.8, 16.8, 13.7, 5.7, 38.6,
15.3, 0, 1.9, 20, 15.4), class = "difftime", units = "days"),
ShopTimeTrue = c(3.4, 4.8, 3.3, 4.4, 5.4, 5.2, 3.4, 5.6,
4.3, 5.6)), .Names = c("Incoming.P.N", "Hold.Time.Quote",
"Hold.Time.Other", "Shop.Time", "Quantity", "HoldTimeQuoteTrue",
"HoldTimeOtherTrue", "ShopTimeTrue"), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame"))
更新的代碼:
highchart() %>%
hc_add_series(TopPN, "column", hcaes(x = Incoming.P.N, y = 21), name = "DIH Goal", color = "#ffffff", borderColor = "#C8C8C8", borderWidth = 2, pointPadding = -0.1,
tooltip = list(pointFormat = "DIH Goal: 21 days<br>")) %>%
hc_add_series(TopPN, "column", hcaes(x = Incoming.P.N, y = round(Hold.Time.Quote,1)), name = "Quote Hold Time", color = "#FF8888",
tooltip = list(pointFormat = "<span style='color:{point.color}'>\u25CF</span> Quote Hold Time: {point.HoldTimeQuoteTrue} days<br>")) %>%
hc_add_series(TopPN, "column", hcaes(x = Incoming.P.N, y = round(Hold.Time.Other,1)), name = "Other Hold Time", color = "#E5A919",
tooltip = list(pointFormat = "{point.color} Other Hold Time: {point.HoldTimeOtherTrue} days<br>")) %>%
hc_add_series(TopPN, "column", hcaes(x = Incoming.P.N, y = round(Shop.Time,1)), name = "Shop Time", color = "#51C1BC",
tooltip = list(pointFormat = "Shop Time: {point.ShopTimeTrue} days<br>Volume: {point.Quantity}")) %>%
hc_xAxis(type = "category") %>%
hc_yAxis(title = "days", labels = list(format = "{value} days")) %>%
hc_tooltip(crosshairs = TRUE, shared = TRUE,
headerFormat = "<b>PN {point.key}</b><br>"
) %>%
hc_plotOptions(column = list(grouping = FALSE, events = list(click = ClickFunctionCustReviewPN)))
您是否考慮過使用繪圖線來說明您的目標及其與數據的關系,而不是使用分組列的技巧? 由於您的目標數據是一致的,因此這可能是更具可讀性的指標。 而且,由於它不在圖表中,因此不會干擾工具提示。
這是對Highcharts堆積柱形圖演示的修改,帶有示例繪圖線: https : //jsfiddle.net/brightmatrix/v3e7gouz/
yAxis: {
...
plotLines: [{
color: 'red',
value: 5, // the value on the y-axis were you want the line to appear
width: 2,
zIndex: 1 // set this value to have the line appear above the y-axis gridline but below the column bars
}],
...
}
希望對您有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.