Skip to content

xo/echartsgoja

Repository files navigation

echartsgoja

echartsgoja renders Apache ECharts as SVGs using the goja JavaScript runtime. Developed for use by usql for rendering charts.

Overview | TODO | About

Unit Tests Go Reference Discord Discussion

Overview

Install in the usual Go fashion:

$ go get github.com/xo/echartsgoja@latest

Then use like the following:

package echartsgoja_test

import (
	"context"
	"log"
	"os"

	"github.com/xo/echartsgoja"
)

func Example() {
	echarts := echartsgoja.New()
	svg, err := echarts.RenderOptions(context.Background(), simpleOpts)
	if err != nil {
		log.Fatal(err)
	}
	if err := os.WriteFile("simple.svg", []byte(svg), 0o644); err != nil {
		log.Fatal(err)
	}
	// Output:
}

const simpleOpts = `{
  "xAxis": {
    "type": "category",
    "boundaryGap": false,
    "data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
  },
  "yAxis": {
    "type": "value"
  },
  "series": [{
    "data": [820, 932, 901, 934, 1290, 1330, 1320],
    "type": "line",
    "areaStyle": {}
  }]
}`

TODO

  • Rewrite as native Go

About

echartsgoja was written primarily to support these projects:

  • usql - a universal command-line interface for SQL databases

Users of this package may find the github.com/xo/resvg package helpful in rendering generated SVGs.