Skip to content

Instantly share code, notes, and snippets.

@parth-patil
Created August 8, 2023 08:16
Show Gist options
  • Save parth-patil/fc49258cd10f34fce538557c30d3e198 to your computer and use it in GitHub Desktop.
Save parth-patil/fc49258cd10f34fce538557c30d3e198 to your computer and use it in GitHub Desktop.
defmodule LbEcharts do
@moduledoc """
Library to use Echarts in LiveBook
"""
use Kino.JS
asset "main.js" do
"""
export async function init(ctx, chart_data) {
await ctx.importJS("https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js");
ctx.root.innerHTML = `
<div id="echart_window" style="width: 800px;height:500px;"></div>`
var myChart = echarts.init(document.getElementById('echart_window'));
// Specify the configuration items and data for the chart
var options = JSON.parse(chart_data);
// Display the chart using the configuration items and data just specified.
myChart.setOption(options);
}
"""
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment