Charting library using Echarts for Livebook
If available in Hex, the package can be installed
by adding lb_echarts
to your list of dependencies in mix.exs
:
def deps do
[
{:lb_echarts, git: "https://github.com/parth-patil/lb_echarts.git"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/lb_echarts.
options = %{
x: ["Shirts", "Cardigans", "Chiffons", "Pants", "Heels", "Socks"],
y: [5, 20, 36, 10, 10, 20],
title: "My exmaple chart",
legend: ["sales", "input"]
}
LbEcharts.bar(options)
get_rand_nums = fn quantity, start_range, end_range ->
1..quantity
|> Enum.map(fn _i ->
start_range..end_range |> Enum.random()
end)
end
stacked_bar_options = %{
title: "My Stacked Bar Chart",
legend: [
"Email",
"Union Ads",
"Video Ads",
"Direct",
"Search Engine"
],
categories: [
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun"
],
orientation: "horizontal", # Change to "vertical" for vertical orientation
stacked_data: %{
"Email" => get_rand_nums.(7, 200, 300),
"Union Ads" => get_rand_nums.(7, 200, 300),
"Video Ads" => get_rand_nums.(7, 100, 300),
"Direct" => get_rand_nums.(7, 150, 300),
"Search Engine" => get_rand_nums.(7, 200, 300)
}
}
LbEcharts.stacked_bar(stacked_bar_options)
response = Req.get!("https://echarts.apache.org/examples/data/asset/data/product.json")
%{body: sankey_data} = response
sankey_opts = %{
num_levels: 3,
nodes: sankey_data["nodes"],
links: sankey_data["links"]
}
LbEcharts.sankey(sankey_opts)