Find a file
2022-02-19 12:35:11 +08:00
.github/workflows docs: add document for echarts option 2021-12-25 12:13:32 +08:00
assets docs: update readme 2022-02-19 10:23:13 +08:00
examples fix: fix write file for go version < 1.16 2022-02-19 10:38:38 +08:00
.gitignore docs: update readme 2022-02-19 10:23:13 +08:00
axis.go feat: support install font and enhance title padding 2022-02-15 23:38:35 +08:00
axis_test.go feat: support make point and make line 2022-02-10 23:24:30 +08:00
bar.go test: add test for legend and draw 2022-02-06 10:40:05 +08:00
bar_chart.go test: add test for echart 2022-02-17 22:53:12 +08:00
bar_chart_test.go test: add test for echart 2022-02-17 22:53:12 +08:00
bar_test.go feat: support line chart draw function 2022-01-29 11:16:34 +08:00
chart.go test: add test for echart 2022-02-17 22:53:12 +08:00
chart_test.go test: add test for echart 2022-02-17 22:53:12 +08:00
draw.go test: add test for echart 2022-02-17 22:53:12 +08:00
draw_test.go test: fix test 2022-02-12 13:01:37 +08:00
echarts.go docs: update readme 2022-02-19 10:23:13 +08:00
echarts_test.go test: fix test 2022-02-19 09:26:11 +08:00
font.go feat: support install font and enhance title padding 2022-02-15 23:38:35 +08:00
font_test.go feat: support install font and enhance title padding 2022-02-15 23:38:35 +08:00
go.mod test: fix test 2022-02-19 09:26:11 +08:00
go.sum refactor: add examples 2021-12-25 09:29:39 +08:00
legend.go feat: support install font and enhance title padding 2022-02-15 23:38:35 +08:00
legend_test.go test: add test for echart 2022-02-17 22:53:12 +08:00
LICENSE Initial commit 2021-12-09 20:20:33 +08:00
line.go feat: support line chart draw function 2022-01-29 11:16:34 +08:00
line_chart.go feat: support echart options 2022-02-16 22:51:02 +08:00
line_chart_test.go test: fix test 2022-02-19 09:26:11 +08:00
line_test.go feat: support line chart draw function 2022-01-29 11:16:34 +08:00
Makefile test: add test for axis 2021-12-18 20:09:02 +08:00
mark_line.go test: add test for bar chart 2022-02-12 14:35:27 +08:00
mark_line_test.go test: add test for bar chart 2022-02-12 14:35:27 +08:00
mark_point.go test: add test for bar chart 2022-02-12 14:35:27 +08:00
mark_point_test.go test: add test for echart 2022-02-17 22:53:12 +08:00
pie_chart.go test: add test for chart 2022-02-12 16:12:02 +08:00
pie_chart_test.go test: add test for chart 2022-02-12 16:12:02 +08:00
range.go refactor: add examples of chart 2022-02-12 11:22:08 +08:00
range_test.go test: fix test 2022-02-12 13:01:37 +08:00
README.md docs: update readme 2022-02-19 12:35:11 +08:00
README_zh.md docs: update readme 2022-02-19 12:35:11 +08:00
series.go feat: support echart options 2022-02-16 22:51:02 +08:00
series_test.go test: add test for pie chart 2022-02-12 15:25:39 +08:00
theme.go refactor: support more color palette 2022-02-18 23:12:31 +08:00
theme_test.go refactor: support more color palette 2022-02-18 23:12:31 +08:00
title.go feat: support install font and enhance title padding 2022-02-15 23:38:35 +08:00
title_test.go feat: support install font and enhance title padding 2022-02-15 23:38:35 +08:00
util.go feat: support echart options 2022-02-16 22:51:02 +08:00
util_test.go feat: support echart options 2022-02-16 22:51:02 +08:00
xaxis.go refactor: add examples of chart 2022-02-12 11:22:08 +08:00
xaxis_test.go test: fix test 2022-02-12 13:01:37 +08:00
yaxis.go refactor: add examples of chart 2022-02-12 11:22:08 +08:00
yaxis_test.go feat: support make point and make line 2022-02-10 23:24:30 +08:00

go-charts

license Build Status

中文

go-charts base on go-chartit is simpler way for generating charts, which supports svg and png format and three themes: light, dark and grafana.

Apache ECharts is popular among Front-end developers, so go-charts supports the option of Apache ECharts. Developers can generate charts almost the same as Apache ECharts.

Screenshot of common charts, the left part is light theme, the right part is grafana theme.

go-charts

Chart Type

Support three chart types: line, bar and pie.

Example

The example is for golang option and echarts option, more examples can be found in the ./examples/ directory.

package main

import (
	"os"
	"path/filepath"

	charts "github.com/vicanso/go-charts"
)

func writeFile(file string, buf []byte) error {
	tmpPath := "./tmp"
	err := os.MkdirAll(tmpPath, 0700)
	if err != nil {
		return err
	}

	file = filepath.Join(tmpPath, file)
	err = os.WriteFile(file, buf, 0600)
	if err != nil {
		return err
	}
	return nil
}

func chartsRender() ([]byte, error) {
	d, err := charts.Render(charts.ChartOption{
		Type: charts.ChartOutputPNG,
		Title: charts.TitleOption{
			Text: "Line",
		},
		XAxis: charts.NewXAxisOption([]string{
			"Mon",
			"Tue",
			"Wed",
			"Thu",
			"Fri",
			"Sat",
			"Sun",
		}),
		SeriesList: charts.SeriesList{
			charts.NewSeriesFromValues([]float64{
				150,
				230,
				224,
				218,
				135,
				147,
				260,
			}),
		},
	})
	if err != nil {
		return nil, err
	}
	return d.Bytes()
}

func echartsRender() ([]byte, error) {
	return charts.RenderEChartsToPNG(`{
		"title": {
			"text": "Line"
		},
		"xAxis": {
			"data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
		},
		"series": [
			{
				"data": [150, 230, 224, 218, 135, 147, 260]
			}
		]
	}`)
}

type Render func() ([]byte, error)

func main() {
	m := map[string]Render{
		"charts-line.png":  chartsRender,
		"echarts-line.png": echartsRender,
	}
	for name, fn := range m {
		buf, err := fn()
		if err != nil {
			panic(err)
		}
		err = writeFile(name, buf)
		if err != nil {
			panic(err)
		}
	}
}

Performance

BenchmarkMultiChartPNGRender-8                78          15216336 ns/op         2298308 B/op       1148 allocs/op
BenchmarkMultiChartSVGRender-8               367           3356325 ns/op        20597282 B/op       3088 allocs/op