# `LiveCharts.Adapter`
[🔗](https://github.com/stax3/live_charts/blob/v0.5.0/lib/live_charts/adapter.ex#L1)

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.

```elixir
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
```

# `build_config`

```elixir
@callback build_config(LiveCharts.Chart.t()) :: map()
```

Translate a `%Chart{}` struct to JS library-specific options

# `hook`

```elixir
@callback hook(LiveCharts.Chart.t()) :: String.t()
```

Fully qualified name of the LiveView hook to call when rendering
the chart.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
