Skip to content

randyzwitch/ECharts.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

593 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ECharts.jl

CI

A Julia wrapper around the Apache ECharts JavaScript visualization library, designed to make interactive charts easy to create with minimal code.

Documentation: https://randyzwitch.com/ECharts.jl/

Why ECharts.jl?

Most Julia plotting libraries either produce static images or require verbose configuration to get basic interactivity. ECharts.jl takes a different approach: it generates rich, interactive browser-based charts (hover tooltips, zoom sliders, toolbox, themes) from simple Julia function calls, while staying out of your way when you just need a quick visualization.

The API is intentionally opinionated — sensible defaults handle the boilerplate so you can focus on your data:

  • A legend only appears when there are two or more series
  • Tooltip-on-hover is enabled automatically
  • Common chart options (stacking, smoothing, flipping axes) are one function call away
  • missing values are handled natively

Chart Types

Category Charts
Basic bar, line, area, differencearea, scatter, bubble, effectscatter, lollipop, slope, dumbbell, divergingbar, singleaxis
Statistical histogram, box, corrplot, ecdfplot, qqplot, forestplot, streamgraph, beeswarm, ridgeline, violin, bump
Part-of-whole pie, donut, funnel, waterfall, radialbar, nightingale, marimekko
Hierarchical / Network treemap, sunburst, tree, sankey, graph, arcdiagram, chord
Geographic choropleth, geoscatter, geoheatmap, geolines
Specialized candlestick, gauge, radar, polar, parallel, heatmap, calendarheatmap, punchcard, gantt, bullet, spanchart, populationpyramid, xy_plot, polarbar

Workflow

  1. Call a chart function with your data to get an EChart object
  2. (Optional) Apply mutating functions (ending in !) to modify the chart
  3. (Optional) Directly set fields on the EChart struct for fine-grained control
using ECharts

x = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
y = [11, 11, 15, 13, 12, 13, 10]

# Step 1: create base chart
ar = area(x, y, color = lineargradient("purple", "cyan"))

# Step 2: modify it
smooth!(ar)
xaxis!(ar, name = "Day of Week")
yaxis!(ar, name = "Daily High Temperature °C")

Faceted / Small-Multiples Charts

facet! splits any multi-series chart into a trellis of panels — one per series — while preserving all styling already applied to the chart. facet is a convenience form for building and faceting in one step.

# Split a grouped bar chart into panels
bar(df, :month, :sales, :region) |> facet!

# Apply styling first, then facet into a 2-column grid
ec = line(df, :quarter, :revenue, :product)
smooth!(ec)
colorscheme!(ec, ("Paired", 12))
facet!(ec; ncols = 2)

# Works with any chart type that supports a group column
scatter(df, :height, :weight, :sex) |> facet!

Mutating Functions

Chart appearance and behavior can be modified after creation:

Color & Themes

Color schemes come from ColorBrewer.jl and NoveltyColors.jl, or you can pass gradient functions like lineargradient directly.

Fifteen pre-built themes are included: chalk, dark, essos, halloween, infographic, macarons, roma, purplepassion, shine, vintage, walden, westeros, wonderland, grayscale, and more. Custom themes can be created via the Theme struct or loaded from ECharts theme builder JSON.

Output

Charts render automatically based on the environment:

Environment Behavior
VS Code (Julia extension) Inline in the plot panel
IJulia / Jupyter Notebook & JupyterLab Inline in the notebook cell
Pluto.jl Inline in the notebook cell
Julia REPL Not supported (use VS Code or Jupyter)

No configuration required — displaying a chart is as simple as evaluating an EChart value in any of these environments.

Live / real-time charts

livechart wraps any EChart in a local HTTP server and returns an EChartLive object. Call update! with new data to push changes to the browser without reloading the page — useful for dashboards and streaming data.

ec = bar(["A", "B", "C"], [1, 2, 3])
lc = livechart(ec)               # opens in browser, starts polling server

update!(lc, bar(["A", "B", "C"], [4, 1, 6]))   # chart updates in place

Saving charts to disk

Use savefig to write a chart to a file. Three formats are supported:

Format Extension Notes
HTML .html Self-contained file with bundled ECharts JS — open in any browser
JSON .json Raw ECharts option payload — useful for embedding or further processing
SVG .svg Server-side rendered via NodeJS.jl — no browser required, suitable for CI/headless environments
using ECharts

chart = bar(["A", "B", "C"], [1, 2, 3])

savefig("chart.html", chart)   # interactive HTML
savefig("chart.json", chart)   # ECharts option JSON
savefig("chart.svg", chart)    # static SVG (server-side rendered)

SVG export uses ECharts' built-in renderToSVGString SSR API and requires NodeJS.jl to be installed. It is loaded lazily — there is no startup overhead when only using HTML or JSON output.

Geographic Maps

All geographic chart types (choropleth, geoscatter, geoheatmap, geolines) share a common map and geojson interface:

  • map = "world" (default): uses the built-in world map
  • 215 country/region maps (e.g. "Germany", "USA", "Antigua_and_Barbuda"): loaded automatically from the bundled artifact — no extra downloads needed
  • Custom GeoJSON: pass a raw GeoJSON string via geojson and a name via map to register any map
# World choropleth
choropleth(country_names, values)

# Country-level map — loaded from bundled artifact
choropleth(state_names, values; map = "USA")

# Custom GeoJSON from disk
geojson_str = read("my_regions.geojson", String)
choropleth(region_names, values; map = "My Regions", geojson = geojson_str)

# Points on a map
geoscatter(lon, lat)
geoscatter(lon, lat, value)          # colour-coded by value

# Heatmap on a map
geoheatmap(lon, lat, intensity)

# Flow lines between coordinates
geolines(start_lon, start_lat, end_lon, end_lat)
geolines(start_lon, start_lat, end_lon, end_lat; effect = true)  # animated trail

All four functions also accept a roam = true keyword to enable pan and zoom.

Tables.jl Support

Most chart functions accept any Tables.jl-compatible table alongside column symbols, making it easy to plot tabular data without pre-processing. This includes DataFrame, CSV.File, TypedTables.Table, a NamedTuple of vectors, and more:

bar(df, :category, :value)
bar(df, :category, :value, :group)  # grouped/stacked by a third column

About

Julia package for the Apache ECharts v6 visualization library

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors