setTooltip: Set 'tooltip' of Echarts

Description Usage Arguments Value Note References Examples

View source: R/options.R

Description

Set tooltip of Echarts, at various levels (entire chart, specific series) with various formats.
When an echart object is generated, you can modify it by setting tooltip using %>%.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
setTooltip(chart, series = NULL, timeslots = NULL, trigger = NULL,
  formatter = NULL, islandFormatter = "{a} < br/>{b} : {c}",
  position = NULL, enterable = FALSE, axisPointer = NULL,
  textStyle = NULL, showDelay = 20, hideDelay = 100,
  transitionDuration = 0.4, bgColor = "rgba(0,0,0,0.7)",
  borderColor = "#333", borderWidth = 0, borderRadius = 4, show = TRUE,
  ...)

setTT(chart, series = NULL, timeslots = NULL, trigger = NULL,
  formatter = NULL, islandFormatter = "{a} < br/>{b} : {c}",
  position = NULL, enterable = FALSE, axisPointer = NULL,
  textStyle = NULL, showDelay = 20, hideDelay = 100,
  transitionDuration = 0.4, bgColor = "rgba(0,0,0,0.7)",
  borderColor = "#333", borderWidth = 0, borderRadius = 4, show = TRUE,
  ...)

Arguments

chart

echarts object generated by echart or echartR

series

A vector of series indices or names. e.g., c('setosa', 'virginica') or 1:2

timeslots

A vector of time slices indices or names, e.g., c(1990, 1992) or c(1,3). You can also use t as a short form of timeslots.

trigger

Type of trigger, 'item', or 'axis'.

formatter

The format of the tooltip content.

string(template)
  • {a} | {a0}

  • {b} | {b0}

  • {c} | {c0}

  • {d} | {d0} (not applicable for some types)

  • {e} | {e0} (not applicable for some types)

function

the JS list is in the form [params, ticket, callback].

Meanings of {a}, {b}, {c}, {d}...

line, bar, k a (series name), b (category name), c (value)
scatter a (series name), b (data name), c (value array)
map a(series name), b (area name), c (combined value)
pie, radar, gauge, funnel a (series names), b(data item name), c (value), d (pie:percent|radar:indicator)
force, chord
  • nodes: a (series name), b (node name), c (node value), d (node type index);

  • links: a (series name), b (link name), c (link value), d (big node name/index), e (small node/index)

JS Function Param Template...

seriesIndex 0, 1, 2, ...
seriesName 'Monday', 'Tuesday', ...
name 'day1', 'day2', ...
dataIndex 0, 1, 2, ...
data data
value value
percent special //pie
indicator special //radar, force, chord
value2 special2 //force, chord
indicator2 special2 //force, chord
islandFormatter

Formatter of data island for calcualable effect. Can be string (default '{a} <br/>{b} : {c}') or JS function.

position

Can be fixed position array c(x, y) or a JS function, e.g., JS('function([x, y]) {return [newX, newY]}'). Default NULL.

enterable

If users can click into the tooltip for interacions. Default FALSE.

axisPointer

The pointer formatter of axis. Default is a list list(type = "line",
lineStyle = list(color = "#48b", width = 2, type = "solid"),
crossStyle = list(color = "#1e90ff", width = 1, type = "dashed"),
shadowStyle = list(color = "rgba(150,150,150,0.3)", width = "auto", type = "default")
)
.

textStyle

text style of the tooltip. In a list form. Default list(color ="#fff"). The list coud contain elements of color, decoration, fontSize, fontFamily, fontStyle, fontWeight, align, baseline.

showDelay

Delayed time at show (ms). Default 20ms.

hideDelay

Delayed time at hide (ms). Default 100ms.

transitionDuration

The time spent at animation exchange. Default 0.4. Set if 0 if you want real-time interaction.

bgColor

Background color of tooltips. Default 'rgba(0,0,0,0.7)' ( semi-transparent dark gray).

borderColor

Borderline color of the tooltips. Default '#333'.

borderWidth

Border width of the tooltips. Default 0 (not shown).

borderRadius

Border radius of the tooltips. Default 4px.

show

Logical. If the tooltips are shown. Default TRUE.

...

Elipsis

Value

A modified echarts object

Note

Note that the tooltip feature is inheritable in terms of timeline. setTooltip automatically breaks the inheritability by resetting tooltip formats in the timeslots following the timeslots whose tooltip format are changed. .

References

http://echarts.baidu.com/echarts2/doc/option.html#title~tooltip

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## Not run: 
g = echartR(iris, Sepal.Width, Petal.Width, series=Species)

## global tooltip
g %>% setTooltip(trigger='item', bgColor='rgba(0,0,200,0.7)')

## series-specific tooltip
bg = sapply(c('orange', 'deepskyblue', 'violet'), col2rgb)
bg = rbind(bg, 0.7)  # extend the color matrix with alpha 0.7
bgCol = unname(apply(bg, 2, rgba))  # get rgba colors with alpha
g %>% setTooltip(series='setosa', bgColor=bgCol[1]) %>%
      setTooltip(series=2, bgColor=bgCol[2]) %>%
      setTooltip(series=3, bgColor=bgCol[3])

## series-and-timeline-specific tooltip
bg = sapply(c('orange', 'deepskyblue', 'violet'), col2rgb)
bg = rbind(bg, 0.7)  # extend the color matrix with alpha 0.7
bgCol = unname(apply(bg, 2, rgba))  # get rgba colors with alpha
iris$tag = 1 + as.integer(row.names(iris)) %% 3
iris = iris[order(iris$tag),]
g1 = echartR(iris, Sepal.Width, Petal.Width, series=Species, t=tag)
g1 %>% setTooltip(series='setosa', bgColor=bgCol[1]) %>%
       setTooltip(series=2, bgColor=bgCol[2]) %>%
       setTooltip(series=3, bgColor=bgCol[3]) %>%
       setTooltip(t=1, borderColor='red', borderWidth=3) %>%
       setTooltip(t=2, borderColor='gold', borderWidth=3) %>%
       setTooltip(t=3, borderColor='green', borderWidth=3)

g1 %>% setTooltip(series=2, t=2, bgColor='blue')
# tooltip format of series 2 in the 2nd timeslot is changed to bg blue,
# while it in the 3rd timeslot is reset to default

## End(Not run)

madlogos/recharts2 documentation built on May 21, 2019, 11:03 a.m.