echarts

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2024 License: MIT Imports: 11 Imported by: 0

README

Apache ECharts for Jupyter Notebooks with Go

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 include examples.ipynb for examples.

Screenshots:

Note: These are just frozen screen captures. If you open the Examples Notebook in Jupyter Notebook, mouse over will interact with the charts. Unfortunately, GitHub won't display the plots in the notebook itself because it won't execute javascript in the notebooks.

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.

Documentation

Overview

Package echarts provides a convenient rendering of [go-echarts](https://github.com/go-echarts/go-echarts) charts and plots for GoNB. It is a wrapper for [Apache ECharts](https://echarts.apache.org/en/index.html).

It defines two methods to display [go-echarts](https://github.com/go-echarts/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 include `examples.ipynb` for examples.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Display

func Display[T SupportedCharts](chart *T, style string) error

Display displays the EChart in GoNB. The parameter `style` is used for the `<div>` tag that holds the plot. Typically, one will want to set the `width` and `height`. E.g.: `style="width: 1024px; height:600px; background: white;"`.

func DisplayContent added in v0.1.0

func DisplayContent[T SupportedCharts](chart *T, style string) (html string, err error)

DisplayContent returns the HTML content (including a `<script>` tag) that displays the EChart in GoNB. One can used Display to display it directly, but if one wants to compose or change the layout, one can use this instead.

The parameter `style` is used for the `<div>` tag that holds the plot. Typically, one will want to set the `width` and `height`. E.g.: `style="width: 1024px; height:600px; background: white;"`.

Types

type Renderer

type Renderer interface {
	Render(w io.Writer) error
}

Renderer interface for echarts that implement the `Render` method.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL