go-echarts
If a language can be used to build web scrapers, it definitely needs to provide a graceful data visualizing library. --- by dongdong.
In the Golang ecosystem, there are not many choices for data visualizing libraries. The development of go-echarts aims to provide a simple yet powerful data visualizing library for Golang. Echarts is an outstanding charting and visualizing library opensourced by Baidu, it supports adorable chart types and various interactive features. There are many language bindings for Echarts, for example, pyecharts. go-echarts learns from pyecharts and has evolved a lot.
🔰 Installation
Classic way to get go-echarts
$ go get -u github.com/go-echarts/go-echarts/...
# this may be a stupid way to use v2 go-echarts without gomod because of
# the gomod version management system... �?�
# if you get a better workaround, please let me know....
$ cd $go-echarts-project
$ mkdir v2 && mv charts components datasets opts render templates types v2Use gomod style
require "github.com/go-echarts/go-echarts/v2"�?� Version
The go-echarts project is being developed under v2 version and the codebase is on the master branch now.
v1 and v2 is incompatible which is mean that you cannot upgrade go-echarts from v1 to v2 smoothly. But I think is worth trying the new version.
✨ Features
- Clean and comprehensive API.
- Visualize your data in 25+ different ways.
- Highly configurable chart options.
- Detailed documentation and a rich collection of examples.
- Visualize your geographical data with 400+ maps.
�? Usage
It's easy to get started with go-echarts. In this example, we create a simple bar chart with only a few lines of code.
package main
import (
"math/rand"
"os"
"github.com/go-echarts/go-echarts/v2/charts"
"github.com/go-echarts/go-echarts/v2/opts"
)
// 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
}
func main() {
// create a new bar instance
bar := charts.NewBar()
// set some global options like Title/Legend/ToolTip or anything else
bar.SetGlobalOptions(
charts.WithTitleOpts(opts.Title{
Title: "Bar-basic-example",
Subtitle: "This is the subtitle.",
}),
)
// iowriter
f, err := os.Create("bar.html")
if err != nil {
panic(err)
}
// Put some data in instance
bar.SetXAxis([]string{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}).
AddSeries("Category A", generateBarItems()).
AddSeries("Category B", generateBarItems())
// Where the magic happens
bar.Render(f)
}And the generated bar.html is rendered as below. Isn't that cool�?
🔖 Gallery
For more information, please refer to go-echarts/examples and the GoDoc.
📃 License
MIT ©chenjiandongx

























