View Source LiveCharts.Adapter behaviour (live_charts v0.4.0)
LiveCharts adapter specification.
Adapter is a module that translates %LiveCharts.Chart{}
struct
into a JS charting library specific configuration. It will usually
expose a LiveView hook to handle dynamic data updates as well.
Right now, LiveCharts ships with only one adapter:
LiveCharts.Adapter.ApexCharts
(default).
Example
To define a new adapter for your favorite JS charting library, or
override the Hook or options, you must call use LiveCharts.Adapter
and implement the required callbacks.
defmodule MyCustomChartAdapter do
use LiveCharts.Adapter
@impl true
def hook, do: "MyCustomChartHook"
@impl true
def build_config(%Chart{} = chart) do
# return a plain map representing the JS library config
# that should be passed to the hook
%{
my_js_lib: %{
chart_type: chart.type,
chart_data: chart.data,
# ...
}
}
end
end
Summary
Callbacks
Translate a %Chart{}
struct to JS library-specific options
Fully qualified name of the LiveView hook to call when rendering the chart.
Callbacks
@callback build_config(LiveCharts.Chart.t()) :: map()
Translate a %Chart{}
struct to JS library-specific options
@callback hook(LiveCharts.Chart.t()) :: String.t()
Fully qualified name of the LiveView hook to call when rendering the chart.