Apache ECharts for Jupyter Notebooks with Go (Examples)
This package adds Go Notebook support to Apache ECharts using GoNB Jupyter kernel and github.com/go-echarts/go-echarts.
It defines two methods to display go-echarts charts: Display
that immediately display the chart, and DisplayContent
that returns the HTML content needed to generate
the chart -- useful for instance if the chart needs to be laid out inside other HTML content.
See included examples -- Notebook file (without the rendered images) in examples.ipynb
.
Note: being just screenshots these are not animated -- see examples for animated version.
import (
"math/rand"
"github.com/go-echarts/go-echarts/v2/charts"
"github.com/go-echarts/go-echarts/v2/opts"
gonb_echarts "github.com/janpfeifer/gonb-echarts"
)
// generate random data for bar chart
func generateBarItems() []opts.BarData {
items := make([]opts.BarData, 0)
for i := 0; i < 7; i++ {
items = append(items, opts.BarData{Value: rand.Intn(300)})
}
return items
}
%%
bar := charts.NewBar()
// set some global options like Title/Legend/ToolTip or anything else
bar.SetGlobalOptions(charts.WithTitleOpts(opts.Title{
Title: "My first bar chart generated by go-echarts",
Subtitle: "It's extremely easy to use, right?",
}))
// Put data into instance
bar.SetXAxis([]string{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}).
AddSeries("Category A", generateBarItems()).
AddSeries("Category B", generateBarItems())
// Display
err := gonb_echarts.Display(bar, "width: 1024px; height:400px; background: white;")
if err != nil {
fmt.Printf("Error: %+v\n", err)
}
Because the charts depend on Javascript, they won't display in GitHub. But exporting notebooks to HTML using JupyterLab will correctly include the charts.
Please, use github.com/janpfeifer/gonb repository.