A validated ECharts chart specification.
A chart wraps a raw ECharts option map together with the rendering options shared by every integration (Livebook, Phoenix LiveView and static HTML).
Charts are immutable values. Build one with ECharts.new/2 (or one of the
ECharts.Express helpers) and pass it to the integration of your choice:
chart = ECharts.new(%{series: [%{type: "line", data: [1, 3, 2]}]})
ECharts.Kino.render(chart)
# or, in a LiveView template:
# <.echarts id="sales" chart={chart} />The option map is validated only at the boundaries this library owns: it must be a map, and the rendering options must have valid types. ECharts validates the option internals in the browser, so new series types work without a package release.
Summary
Functions
Builds a chart from a raw ECharts option map.
Returns the raw ECharts option map.
Returns the payload as a JSON string.
Returns the payload consumed by the JavaScript clients.
Types
Functions
Builds a chart from a raw ECharts option map.
Options
:height- chart height in pixels, defaults to420:theme-:light(the ECharts default),:dark(the built-in dark theme), a custom theme name, or a theme map. UseECharts.Theme.light/0orECharts.Theme.dark/0for a ready-made palette map:renderer-"canvas"(default) or"svg". SVG is useful for crisp screenshots and printing; canvas is faster for large series. ECharts GL requires canvas:gl- set totrueto load the bundledecharts-glextension forbar3D,scatter3D,line3D,surface,globe,map3D,lines3D,polygons3D,scatterGL,graphGLandflowGLcharts:maps- map ofname => GeoJSONregistered before rendering, formap,map3D,lines3Dandpolygons3Dcharts:plugins- bundled extensions to load:"wordcloud"forwordCloudseries and"liquidfill"forliquidFillseries:functions- map of callback name to JavaScript source. Use%{"$function" => "name"}in the option where ECharts expects a function, such as acustomseries'renderItem:events- browser events forwarded by the integrations, defaults to["click", "legendselectchanged"]. Pass:allfor every event listed inECharts.Events.all/0, or[]to disable forwarding
Examples
ECharts.new(
%{
xAxis: %{type: "category", data: ["a", "b", "c"]},
yAxis: %{type: "value"},
series: [%{type: "bar", data: [1, 3, 2]}]
},
height: 300,
theme: :dark
)
Returns the raw ECharts option map.
Returns the payload as a JSON string.
Returns the payload consumed by the JavaScript clients.
The payload is a plain map, safe to send through Kino or JSON-encode for a Phoenix data attribute.