【发布时间】:2017-09-25 17:13:36
【问题描述】:
我在让 plotlys hoverinfo 属性仅显示堆叠条形图的一个条形的单个部分时遇到了一些麻烦。更准确地说,这里有一个来自 plotly 主页的小例子:
library(plotly)
y <- c('giraffes', 'orangutans', 'monkeys')
SF_Zoo <- c(20, 14, 23)
LA_Zoo <- c(12, 18, 29)
data <- data.frame(y, SF_Zoo, LA_Zoo)
plot_ly(data, x = ~SF_Zoo, y = ~y, type = 'bar', orientation = 'h', name = 'SF Zoo',
marker = list(color = 'rgba(246, 78, 139, 0.6)',
line = list(color = 'rgba(246, 78, 139, 1.0)',
width = 3))) %>%
add_trace(x = ~LA_Zoo, name = 'LA Zoo',
marker = list(color = 'rgba(58, 71, 80, 0.6)',
line = list(color = 'rgba(58, 71, 80, 1.0)',
width = 3))) %>%
layout(barmode = 'stack',
xaxis = list(title = ""),
yaxis = list(title =""))
如果我将鼠标移到一个栏上,则会显示两个标签:
有没有办法在我将鼠标移动到灰色条上时只显示灰色条的标签,当我将鼠标移动到粉色条上时显示粉色标签,等等?
【问题讨论】:
-
如果我清楚地记得我在 Plotly 中制作的图表,您只需单击 plotly 徽标中的第三个大箭头,它就会使其成为单次悬停。右侧的双箭头使其在栏中显示两个数据集。