KinoECharts

Apache ECharts charts for Livebook, with no Vega-Lite layer in between.

KinoECharts renders a raw ECharts option map. That keeps the full ECharts surface available: candlesticks, dataZoom, financial tooltips, multiple grids, custom axes and any series type ECharts supports. The ECharts 6 bundle is vendored, so charts work offline.

Installation

Mix.install([{:kino_echarts, "~> 0.7"}])

For development against a checkout:

Mix.install([{:kino_echarts, path: "/path/to/kino_echarts"}])

Usage

KinoECharts.new(%{
  xAxis: %{type: "category", data: ["Mon", "Tue", "Wed", "Thu", "Fri"]},
  yAxis: %{type: "value"},
  series: [
    %{type: "line", data: [120, 200, 150, 80, 170], smooth: true}
  ]
})

Use KinoECharts.render/2 when you do not need to keep the kino around:

KinoECharts.render(option, height: 360)

Candlestick with volume

ECharts wants OHLC values as [open, close, low, high]:

candles = [
  %{t: "2026-11-24", o: 100.0, h: 106.0, l: 98.0, c: 104.0, v: 1_200},
  %{t: "2026-11-25", o: 104.0, h: 109.0, l: 102.0, c: 107.0, v: 1_800},
  %{t: "2026-11-26", o: 107.0, h: 108.0, l: 99.0, c: 101.0, v: 2_100}
]

option = %{
  tooltip: %{trigger: "axis"},
  xAxis: %{type: "category", data: Enum.map(candles, & &1.t)},
  yAxis: %{type: "value", scale: true},
  dataZoom: [%{type: "inside", start: 0, end: 100}],
  series: [
    %{
      type: "candlestick",
      data: Enum.map(candles, &[&1.o, &1.c, &1.l, &1.h])
    }
  ]
}

KinoECharts.new(option, height: 420, theme: "dark")

Map

ECharts does not bundle geographic data. Register one or more GeoJSON maps with :maps; the client calls echarts.registerMap/2 before creating the instance:

KinoECharts.new(
  %{
    visualMap: %{min: 0, max: 100, left: 20, bottom: 20},
    series: [
      %{
        type: "map",
        map: "demo",
        data: [
          %{name: "Norte", value: 80},
          %{name: "Sul", value: 45}
        ]
      }
    ]
  },
  maps: %{"demo" => geo_json}
)

Custom series

ECharts callbacks cannot travel as JSON. Pass their source with :functions and use a marker where the function is expected:

render_item = """
function (params, api) {
  const x = api.value(0);
  const y = api.value(1);
  return {
    type: "rect",
    shape: {x: api.coord([x, y])[0], y: 0, width: 20, height: 20},
    style: api.style()
  };
}
"""

KinoECharts.new(
  %{
    xAxis: %{type: "category", data: ["A", "B", "C"]},
    yAxis: %{type: "value"},
    series: [
      %{
        type: "custom",
        renderItem: %{"$function" => "renderItem"},
        data: [[0, 10], [1, 20], [2, 15]]
      }
    ]
  },
  functions: %{"renderItem" => render_item}
)

Functions are compiled with new Function in the browser. Only pass trusted code, just like any other Livebook cell.

Themes

KinoECharts accepts theme: :light and theme: :dark out of the box. :light uses the ECharts default palette and :dark uses the built-in dark theme. Custom theme names and theme maps are passed through to echarts.init/3.

The gallery notebook has a Tema selector; change it and re-evaluate a chart cell to compare light and dark.

KinoECharts gallery

A few of the 39 bundled examples: line, candlestick, 3D bar and word cloud. The gallery starts in light mode to match Livebook's default canvas and the Tema cell switches it to dark. The full gallery includes every 2D family, the GL/geo charts and the optional word cloud/liquid fill extensions.

Charts

The gallery covers every built-in 2D chart family in ECharts 6:

See the gallery notebook for a rendered example of each one.

The optional echarts-gl bundle is vendored in priv/static. It is only loaded when a chart uses gl: true, so 2D charts do not pay for it.

Options

KinoECharts.new(option, opts) accepts:

Option Default Description
:height 420 Chart height in pixels.
:theme nil :light (default), :dark, a custom theme name, or a theme map.
:renderer "canvas" "canvas" or "svg". SVG is useful for printing and crisp screenshots.
:gl false Load echarts-gl for 3D series.
:plugins [] Load bundled extensions: "wordcloud" and/or "liquidfill".
:maps %{} Map of name => GeoJSON registered before rendering, for map/3D series.
:functions %{} Map of callback name to JavaScript source, referenced in the option as %{"$function" => "name"}.

The option map can use atom or string keys. It is JSON-encoded before being sent to the browser, so all values must be JSON-encodable.

Troubleshooting

Security

Livebook assets are public. Never put secrets (API keys, private account data) in the option map. Treat everything you pass to KinoECharts.new/2 as visible to anyone who can load the notebook output.

Development

There are runnable notebooks at examples/basic.livemd and examples/gallery.livemd. Run livebook server examples from the repository root.

mix deps.get
mix format --check-formatted
mix test
mix docs

# Browser smoke for all 39 charts (Chromium + WebGL)
mix run visual/generate.exs
cd visual && npm ci --include=dev
npx playwright install chromium
npx playwright test

Comments in the fixtures explain why an option or data shape is there (especially the GL coordinate systems); the ECharts option itself documents the happy path. Add one fixture per chart family and keep it theme-neutral so both light and dark galleries exercise the same option.

The ECharts bundle lives in priv/static/echarts.min.js (Apache 2.0). The client entrypoint is priv/static/main.js.

License

KinoECharts is released under the MIT License. Apache ECharts is bundled under the Apache License 2.0; see NOTICE.