Apache ECharts charts for Livebook.
This kino renders a raw ECharts option map. It is lower-level than a grammar-of-graphics library on purpose: you get candlesticks, dataZoom, financial tooltips and multi-grid layouts without leaving Elixir or paying for a Vega-Lite abstraction you do not need.
The ECharts bundle is vendored, so charts work offline and do not depend on a CDN.
Usage
Mix.install([{:kino_echarts, "~> 0.1"}])
KinoECharts.new(%{
xAxis: %{type: "category", data: ["Mon", "Tue", "Wed"]},
yAxis: %{type: "value"},
series: [%{type: "line", data: [120, 200, 150]}]
})Options are passed as a map with string or atom keys. They are sent to the browser as JSON, so values must be JSON-encodable.
Assets are public, like any Livebook kino. Never put secrets (API keys, account balances you would not show on screen) in the option map.
Summary
Functions
Builds a kino from an ECharts option map.
Renders the chart immediately and returns the kino.
Types
@type option() :: map()
Functions
Builds a kino from an ECharts option map.
Options
:height- canvas height in pixels, defaults to420:theme-:light(ECharts default light),:dark(built-in dark), a custom theme name, or a theme map:renderer-"canvas"(default) or"svg"; SVG can be useful for crisp screenshots and printing, canvas is faster for large series:gl- set totrueto load the bundledecharts-glextension forbar3D,scatter3D,line3D,surface,map3Dandglobeseries:maps- map ofname => GeoJSONregistered with ECharts before the option is applied. Use this formapseries:functions- map of callback name to JavaScript function source. Use%{"$function" => "name"}in the option where ECharts expects a function, such as acustomseries'renderItem. Functions run in the browser and must be trusted code:KinoECharts.new( %{ series: [ %{ type: "custom", renderItem: %{"$function" => "renderItem"}, data: [[0, 10], [1, 20]] } ] }, functions: %{ "renderItem" => "function (params, api) { ... }" } )
Examples
KinoECharts.new(%{
xAxis: %{type: "category", data: ["a", "b", "c"]},
yAxis: %{type: "value"},
series: [%{type: "bar", data: [1, 3, 2]}]
}, height: 300, theme: "dark")A map chart registers its GeoJSON first:
KinoECharts.new(
%{
series: [%{type: "map", map: "demo", data: [%{name: "A", value: 10}]}]
},
maps: %{"demo" => geo_json}
)
Renders the chart immediately and returns the kino.
This is a convenience for notebook cells where you do not need to keep a reference to the kino:
KinoECharts.render(option, height: 360)