如何在没有注释的情况下显示在dygraph中显示的工具提示

编程入门 行业动态 更新时间:2024-10-24 10:19:28
本文介绍了如何在没有注释的情况下显示在dygraph中显示的工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用dygraphs的R实现

I am trying to use the R implementation of dygraphs

提供的示例是

library(dygraphs) dygraph(presidents, main = "Presidential Approval") %>% dyAxis("y", valueRange = c(0, 100)) %>% dyAnnotation("1950-7-1", text = "A", tooltip = "Korea") %>% dyAnnotation("1965-1-1", text = "B", tooltip = "Vietnam")

导致图表

将鼠标悬停在A上会产生工具提示使用'Korea'

Hovering over the 'A' produces a tooltip with 'Korea'

我希望每个点都有一个工具提示,最好完全符合文本要求 - 尽管将文本设置为具有最小的高度/宽度值可能满足。我还想以编程方式从带有日期和工具提示列的文件中附加dyAnnotations

I am keen to have a tooltip for every point preferably dispensing entirely with the text requirement - though setting text to "" with minimal height/width values might suffice. I would also want to attach the dyAnnotations programmatically from a file with date and tooltip columns

df <- data.frame(date=as.Date(c("1950-7-1","1965-1-1")),tooltip=c("Korea","Vietnam"))

这是可行的,如果是这样,怎么样? TIA

Is this feasible,and, if so, how? TIA

推荐答案

好的,正如所承诺的,这是我们如何使用图例来获取您的信息的开始。我们粗略地覆盖了传说。如果您还想要一个图例,这种行为可以更有礼貌。此外,您可以提供带有 data.frame 的对象/哈希来查找 x 并返回信息性描述。

Alright, as promised, here is a start to how we might use the legend for your information. We crudely overwrite the legend. This behavior can be made much more polite if you also want a legend. In addition, you could provide an object/hash with a data.frame to lookup the x and return an informative description.

我添加了一个调试器所以如果你在Chrome等中打开调试器,你可以看到发生了什么。

I added a debugger so if you open your debugger in Chrome, etc. you can see what is happening.

library(dygraphs) dyG = dygraph(presidents, main = "Presidential Approval") %>% dyAxis("y", valueRange = c(0, 100)) # explore the legend route dyG %>% dyCallbacks( highlightCallback = sprintf( 'function(e, x, pts, row) { // added to illustrate what is happening // remove once satisfied with your code debugger; var customLegend = %s // should get our htmlwidget e.target.parentNode.parentNode .querySelectorAll(".dygraph-legend")[0] .innerText = customLegend[row] + row; }' ,# supply a vector or text that you would like jsonlite::toJSON(rep('something here',length(as.vector(presidents)))) ) )

下面,我已更改为添加到图例而不是替换。

Below, I have changed to add to the legend rather than replace.

# explore the legend route # add to legend rather than replace dyG %>% dyCallbacks( highlightCallback = sprintf( 'function(e, x, pts, row) { // added to illustrate what is happening // remove once satisfied with your code debugger; var customLegend = %s // should get our htmlwidget var legendel = e.target.parentNode.parentNode .querySelectorAll(".dygraph-legend")[0]; // should get our htmlwidget legendel.innerHTML = legendel.innerHTML + "<br>" + customLegend[row]; }' ,# supply a vector or text that you would like jsonlite::toJSON(rep('something here',length(as.vector(presidents)))) ) )

更多推荐

如何在没有注释的情况下显示在dygraph中显示的工具提示

本文发布于:2023-11-22 23:26:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619331.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:注释   情况下   提示   工具   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!