首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >简单地更新直接标签数据

简单地更新直接标签数据
EN

Stack Overflow用户
提问于 2018-10-16 02:59:38
回答 1查看 667关注 0票数 0

我有这样的代码,用直接标签生成条形图,我添加一个按钮切换到另一个数据,但是如何更新直接标签数据。

代码语言:javascript
复制
library(plotly)


chart <- structure(list(Date3 = structure(c(17805, 17806, 17807, 17808
), class = "Date"), Installed_qty_piling = c(9000, 1, 741, 72), Installed_qty_piling_Delivery = c(2592, 
                                                                                                  250, 33, 24)), row.names = c(NA, -4L), class = c("tbl_df", 
                                                                                                                                                   "tbl", "data.frame"))




p <- plot_ly(chart, x = ~Date3, y = ~Installed_qty_piling,text=~Installed_qty_piling,textposition = 'auto', type = "bar",  name = "A", visible = T) %>%
  layout(
    title = "qty installed",
    yaxis = list(title = "qty"),
    updatemenus = list(
      list(
        y = 100,
        buttons = list(
          list(method = "restyle",
               args = list("y", list(chart$Installed_qty_piling)),  # put it in a list
               label = "piling"),
          list(method = "restyle",
               args = list("y", list(chart$Installed_qty_piling_Delivery)),  # put it in a list
               label = "piling Delivery")))
    ))
p
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-20 05:44:56

是的,我在别的地方找到了答案,也需要更新文本。

代码语言:javascript
复制
library(plotly)


chart <- structure(list(Date3 = structure(c(17805, 17806, 17807, 17808
), class = "Date"), Installed_qty_piling = c(9000, 1, 741, 72), 
Installed_qty_piling_Delivery = c(2592, 

250, 33, 24)), row.names = c(NA, -4L), class = c("tbl_df", 

"tbl", "data.frame"))
plot_ly(chart, x = ~Date3, y = 
~Installed_qty_piling,text=~Installed_qty_piling,textposition = 'auto', type = "bar",  
name = "A", visible = T) %>%
layout(
   title = "qty installed",
   yaxis = list(title = "qty"),
updatemenus = list(
  list(
    y = 100,
    buttons = list(
      list(method = "restyle",
           args = list(list(y = list(chart$Installed_qty_piling), text = list(chart$Installed_qty_piling))),
           label = "piling"),
      list(method = "restyle",
           args = list(list(y = list(chart$Installed_qty_piling_Delivery), text = list(chart$Installed_qty_piling_Delivery))), 
           label = "piling Delivery")))
)

)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52827355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档