Livebook integration for ECharts.
The kino renders the chart in place and keeps a small server process, so the chart can be updated without re-evaluating the cell and browser events can be delivered to Elixir.
Rendering
ECharts.Kino.new(%{
xAxis: %{type: "category", data: ["Mon", "Tue", "Wed"]},
yAxis: %{type: "value"},
series: [%{type: "line", data: [120, 200, 150]}]
})Use render/2 when you do not need to keep the kino around:
ECharts.Kino.render(option, height: 360)Live updates
chart = ECharts.Kino.new(option)
for point <- stream do
ECharts.Kino.push(chart, updated_option)
endpush/2 accepts a raw option map or an ECharts.Chart.
Events
The chart forwards the events listed in the :events option (by default
"click" and "legendselectchanged"). Subscribe the current process:
ECharts.Kino.subscribe(chart, :chart_events)
receive do
{:chart_events, %{"type" => "click", "data" => data}} ->
IO.inspect(data)
endSubscribe to a single event type with subscribe(chart, tag, :click), or
subscribe another process with subscribe(chart, pid, tag).
Assets are public. Never put secrets in the option map.
Summary
Functions
Builds a live kino from an ECharts option map or an ECharts.Chart.
Pushes a new chart to every connected client.
Renders the chart immediately and returns the kino.
Subscribes a process to chart events.
Types
@type kino() :: Kino.JS.Live.t()
Functions
@spec new(ECharts.option() | ECharts.Chart.t(), keyword()) :: kino()
Builds a live kino from an ECharts option map or an ECharts.Chart.
Accepts the options of ECharts.new/2 when given an option map.
@spec push(kino(), ECharts.option() | ECharts.Chart.t()) :: :ok
Pushes a new chart to every connected client.
Returns :ok. The update runs asynchronously; the chart is replaced in
place.
@spec render(ECharts.option() | ECharts.Chart.t(), keyword()) :: kino()
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.
Subscribes a process to chart events.
Without a pid, subscribes the calling process. filter is :all
(default) or an event name such as :click.
Messages are sent as {tag, payload} where payload is
%{"type" => event_name, "data" => event_data}.