Home

Awesome

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.

Screenshots:

Note: being just screenshots these are not animated -- see examples for animated version.

Bar Chart (with code)

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)
}

image

Stacked Lines

image

Geo Map example

image

Limitations

Because the charts depend on Javascript, they won't display in GitHub. But exporting notebooks to HTML using JupyterLab will correctly include the charts.

Issues, feature requests, discussions and support

Please, use github.com/janpfeifer/gonb repository.