score:1
After several years, I have an answer.
It seems like these wrapper functions like hPlot()
does not support additional tooltip variables even with a simple custom formatter function. See working example below based on the dataset from the question.
require(rCharts)
# create data frame
df <- data.frame(x = c(1:5), y = c(5:1),
z = c("A", "B", "C", "D", "E"),
name = c("K", "L", "M", "N", "O"))
# Plot using hPlot() approach
h1 <- hPlot(x = "x", y = "y", data = df, type = "scatter", group = "z")
h1$tooltip(borderWidth=0, followPointer=TRUE, followTouchMove=TRUE, shared = FALSE,
formatter = "#! function(){return 'X: ' + this.point.x + '<br>Y: ' + this.point.y + '<br>Z: ' + this.point.z + '<br>Name: ' + this.point.name;} !#")
h1
Tooltips do not work in the above example because the variables in the array are not named. See str(h1)
.
# Plot using manual build
h1 <- rCharts:::Highcharts$new()
dlev <- levels(factor(as.character(df$z)))
for(i in 1:length(dlev))
{
h1$series(data = toJSONArray2(df[df$z==dlev[i],,drop=F], json = F,names=T), name = dlev[i],type = c("scatter"), marker = list(radius = 3))
}
h1$tooltip(borderWidth=0, followPointer=TRUE, followTouchMove=TRUE, shared = FALSE,
formatter = "#! function(){return 'X: ' + this.point.x + '<br>Y: ' + this.point.y + '<br>Z: ' + this.point.z + '<br>Name: ' + this.point.name;} !#")
h1
This works because the array variables are named using names=T
in the line starting h1$series...
. See str(h1)
.
This sort of solves the tooltip issue, but there might be other problems with the named arrays. For example, it breaks things in a shiny-app environment. There must be a reason why hPlot()
does not use the named arrays.
score:3
rCharts
is a great package. But it still not well documented(Maybe I miss this point). I think you need to redefine new JS function for tooltip
attribute.
Any JS literals need to be wrapped between #! and !# . Here a beginning but it doesn't work as I imagine ( I think is a good start):
h1$tooltip( formatter = "#! function() { return 'x: ' + this.point.x +
'y: ' + this.point.y +
'name: ' + this.point.group; } !#")
Source: stackoverflow.com
Related Query
- Add values to rCharts hPlot tooltip
- add to tooltip additional values from array
- rCharts Highcharts Add extra data to tooltip
- hPlot pie chart - show percentage in tooltip instead of absolute values
- highcharts pass multiple values to tooltip
- Add tooltip to legend in highcharts when hovering
- Add additional data to Pie Tooltip on Highcharts
- How do I add a tooltip to the x-axis labels in highcharts?
- Display multiple time series with rCharts hPlot
- Highcharts add tooltip that has a small arrow pointing toward the series
- how to pass values to tooltip which not in x and y axis in highcharts
- Highcharts : Shared Tooltip for non-matching x values
- Highcharts JS- add third variable to tooltip for two series
- How to add % symbol to Y axis values in HighChart graph?
- Highchart: add own calculation to tooltip
- How do i add mouse wheel code in Angular2 highcharts in typescript
- Add extra tooltip in Highcharts
- Unable to apply custom pipe to high chart tooltip values
- How to edit tooltip in Highcharts C# code
- Get values formatted on tooltip
- passing json values to highcharts from .net code behind
- Highcharts variation (%) between yaxis values in tooltip
- how to use highcharts tooltip formatter in python code
- Add a custom text tooltip that differs from point to point in Highcharts
- HighCharts: Category values are repeated. Tooltip not showing the correct date
- add vertical and horizontal lines in hplot (rcharts)
- How to add a second tooltip to highcharts
- High Charts add variance instead of values
- Highcharts - Highcharter in R - Getting Tooltip values from df rather than map
- Add more than 3 y-axis in Highcharts. 4th y-axis values aren't displayed
More Query from same tag
- Customize text stackLabels dynamically Highcharts
- How to reference a data point (or points) in another series in highcharts
- Export Multiple Highcharts to Multi-page PDF
- unable to fetch temperature data in highcharts
- HIghmap colorAxis filter
- HIghcharts seperation of legend and pie
- Highchart Scrollbar position
- Sort series per category
- Hicharts sankey diagram error when looping
- return json arrays from symfony controller for many usage on highcharts.js
- Highcharts dynamic data update fails
- HighCharts SyntaxError: missing ] after element list
- Kendo Linear Guage with logarithmic scale
- Highmaps js, on Hover display additional data
- HighCharts WorlMap datalabel translation
- Highstock tooltip formatter if using split : true
- how to handle mouse over event in legend in highcharts?
- High Charts - area chart with gradient & threshold
- Display Highcharts data from mysql database on jsp page
- Saving images from HTML5 canvas directly
- Highstock navigator not adjustable
- Dock highcharts legend to very bottom of chart
- highchart print chart/chart context menu un-clickable
- How to add additional labels to base of columns in Highcharts?
- Highcharts Treemap: Add link on lowest level
- How to create PIE chart with slice inside outer circle
- How can I configure the legend with a specific height in highstock?
- Cannot give different values to diffrent Bar item click in HighChart
- Highcharts Angular - Sunburst implementation
- Rendering a table with Chart.renderer.text