Learn R Programming

echarty (version 1.4.7)

ec.clmn: Data column

Description

Helper function to display/format data column(s) by index or name

Usage

ec.clmn(col = NULL, ..., scale = 1)

Value

A JavaScript code string (usually a function) marked as executable, see JS.

Arguments

col

A single column index(number) or column name(quoted string),
or a sprintf format string. Default is NULL, for charts with single values like tree, pie.

...

A comma separated column indexes or names, only when col is sprintf. This allows formatting of multiple columns, as for a tooltip.

scale

A positive number, multiplier for numeric columns. When scale is 0, all numeric values are rounded.

Details

Column indexes are counted in R and start at 1.
Omit col or use index -1 for single values tree/pie charts, axisLabel.formatter or valueFormatter. See ec.data dendrogram example.
Use only column index(es) when setting symbolSize.
Column indexes are decimals for combo charts with multiple series, see ecr.band example. The whole number part is the serie index, the decimal part is the column index inside.
col as sprintf has the same placeholder %@ for both column indexes or column names.
col as sprintf can contain double quotes, but not single or backquotes.
Placeholder %L@ will display a number in locale format, like '12,345.09'.
Placeholder %LR@ will display a rounded number in locale format, like '12,345'.
Placeholder %R@ will display a rounded number, like '12345'.
Placeholder %M@ will display a marker in serie's color.
Useful for attributes like formatter, color, symbolSize.

Examples

Run this code
tmp <- data.frame(Species = as.vector(unique(iris$Species)),
                  emoji = c('\U0001F33B','\U0001F335','\U0001F33A'))
df <- iris |> dplyr::inner_join(tmp)      # add 6th column emoji
df |> dplyr::group_by(Species) |> ec.init() |> ec.upd({
  series <- lapply(series,
    function(s) append(s,
      list(label= list(show= TRUE, formatter= ec.clmn('emoji')))) )
  tooltip <- list(formatter=
    # ec.clmn with sprintf + multiple column indexes
    ec.clmn('%M@ species %@s.len %@s.wid %@', 5,1,2))
})

Run the code above in your browser using DataLab