Introduction: Introduction

– Introduction –R Documentation



echarty provides a lean interface between R and Javascript library ECharts.
With only two major commands (ec.init and ec.upd), it can trigger multiple native ECharts options to build a chart.
The benefits - learn a very limited set of commands, and enjoy the full functionality of ECharts.

Package Conventions

  1. pipe-friendly - supports both %>% and |>

  2. commands have three prefixes to help with auto-completion:

  • ec. for general functions, like ec.init

  • ecs. for Shiny functions, like ecs.output

  • ecr. for rendering functions, like

Global Options

Options are set with R command options. Echarty uses the following options:

  • echarty.theme = name of theme file, without extension, from folder /inst/themes

  • echarty.font = font family name

  • echarty.urlTiles = tiles URL template for leaflet maps


Event handling is usually necessary only in Shiny. See code in ec.examples and eshiny.R, run as demo(eshiny).
echarty has two built-in event callbacks - click and mouseover.
All other ECharts events should be initialized through p$x$capture. Another option is to use p$x$on with JavaScript handlers, see code in ec.examples.

Widget ‘x’ parameters

These are htmlwidget and ECharts initialization parameters supported by echarty. There are code samples for most of them in ec.examples.

  • capture = event name(s), to monitor events, usually in Shiny

  • on = define JavaScript code for event handling, see it in ECharts

  • registerMap = define a map from a geoJSON file, see it in ECharts

  • group = group-name of a chart, see it in ECharts

  • connect = command to connect charts with same group-name, see it in ECharts

  • locale = ‘EN’(default) or ‘ZH’, set from locale parameter of ec.init, see it in ECharts.

  • renderer = ‘canvas’(default) or svg, set from renderer in ec.init, see it in ECharts.

  • jcode = custom JavaScript code to execute, set from js parameter of ec.init

R vs Javascript numbering

R indexes are counted starting from 1. JS indexes are counted starting from 0. echarty supports R-counting in series-encode x,y,tooltip and visualMap-continuous dimension when set through ec.init. All other indexes like xAxisIndex, gridIndex, etc. need to be set in JS-counting (for now).

Code examples

Here is the complete list of sample code locations

# basic scatter chart from a data.frame, using presets
cars |> ec.init()

# set/get global options
options('echarty.theme'='jazz') # set
getOption('echarty.theme')      # get
options('echarty.theme'=NULL)   # remove

echarty documentation built on Nov. 24, 2022, 5:06 p.m.