• Stars
    star
    140
  • Rank 261,473 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A charts library for Golang

go-charts

license Build Status

中文

go-charts base on go-chart,it is simpler way for generating charts, which supports svg and png format and themes: light, dark, grafana and ant. The default format is png and the default theme is light.

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

go-table

Chart Type

These chart types are supported: line, bar, horizontal bar, pie, radar or funnel and table.

Example

More examples can be found in the ./examples/ directory.

Line Chart

package main

import (
	charts "github.com/vicanso/go-charts/v2"
)

func main() {
	values := [][]float64{
		{
			120,
			132,
			101,
			134,
			90,
			230,
			210,
		},
		{
			// snip...
		},
		{
			// snip...
		},
		{
			// snip...
		},
		{
			// snip...
		},
	}
	p, err := charts.LineRender(
		values,
		charts.TitleTextOptionFunc("Line"),
		charts.XAxisDataOptionFunc([]string{
			"Mon",
			"Tue",
			"Wed",
			"Thu",
			"Fri",
			"Sat",
			"Sun",
		}),
		charts.LegendLabelsOptionFunc([]string{
			"Email",
			"Union Ads",
			"Video Ads",
			"Direct",
			"Search Engine",
		}, charts.PositionCenter),
	)

	if err != nil {
		panic(err)
	}

	buf, err := p.Bytes()
	if err != nil {
		panic(err)
	}
	// snip...
}

Bar Chart

package main

import (
	"github.com/vicanso/go-charts/v2"
)

func main() {
	values := [][]float64{
		{
			2.0,
			4.9,
			7.0,
			23.2,
			25.6,
			76.7,
			135.6,
			162.2,
			32.6,
			20.0,
			6.4,
			3.3,
		},
		{
			// snip...	
		},
	}
	p, err := charts.BarRender(
		values,
		charts.XAxisDataOptionFunc([]string{
			"Jan",
			"Feb",
			"Mar",
			"Apr",
			"May",
			"Jun",
			"Jul",
			"Aug",
			"Sep",
			"Oct",
			"Nov",
			"Dec",
		}),
		charts.LegendLabelsOptionFunc([]string{
			"Rainfall",
			"Evaporation",
		}, charts.PositionRight),
		charts.MarkLineOptionFunc(0, charts.SeriesMarkDataTypeAverage),
		charts.MarkPointOptionFunc(0, charts.SeriesMarkDataTypeMax,
			charts.SeriesMarkDataTypeMin),
		// custom option func
		func(opt *charts.ChartOption) {
			opt.SeriesList[1].MarkPoint = charts.NewMarkPoint(
				charts.SeriesMarkDataTypeMax,
				charts.SeriesMarkDataTypeMin,
			)
			opt.SeriesList[1].MarkLine = charts.NewMarkLine(
				charts.SeriesMarkDataTypeAverage,
			)
		},
	)
	if err != nil {
		panic(err)
	}

	buf, err := p.Bytes()
	if err != nil {
		panic(err)
	}
	// snip...
}

Horizontal Bar Chart

package main

import (
	"github.com/vicanso/go-charts/v2"
)

func main() {
	values := [][]float64{
		{
			18203,
			23489,
			29034,
			104970,
			131744,
			630230,
		},
		{
			// snip...	
		},
	}
	p, err := charts.HorizontalBarRender(
		values,
		charts.TitleTextOptionFunc("World Population"),
		charts.PaddingOptionFunc(charts.Box{
			Top:    20,
			Right:  40,
			Bottom: 20,
			Left:   20,
		}),
		charts.LegendLabelsOptionFunc([]string{
			"2011",
			"2012",
		}),
		charts.YAxisDataOptionFunc([]string{
			"Brazil",
			"Indonesia",
			"USA",
			"India",
			"China",
			"World",
		}),
	)
	if err != nil {
		panic(err)
	}

	buf, err := p.Bytes()
	if err != nil {
		panic(err)
	}
	// snip...
}

Pie Chart

package main

import (
	"github.com/vicanso/go-charts/v2"
)

func main() {
	values := []float64{
		1048,
		735,
		580,
		484,
		300,
	}
	p, err := charts.PieRender(
		values,
		charts.TitleOptionFunc(charts.TitleOption{
			Text:    "Rainfall vs Evaporation",
			Subtext: "Fake Data",
			Left:    charts.PositionCenter,
		}),
		charts.PaddingOptionFunc(charts.Box{
			Top:    20,
			Right:  20,
			Bottom: 20,
			Left:   20,
		}),
		charts.LegendOptionFunc(charts.LegendOption{
			Orient: charts.OrientVertical,
			Data: []string{
				"Search Engine",
				"Direct",
				"Email",
				"Union Ads",
				"Video Ads",
			},
			Left: charts.PositionLeft,
		}),
		charts.PieSeriesShowLabel(),
	)
	if err != nil {
		panic(err)
	}

	buf, err := p.Bytes()
	if err != nil {
		panic(err)
	}
	// snip...	
}

Radar Chart

package main

import (
	"github.com/vicanso/go-charts/v2"
)

func main() {
	values := [][]float64{
		{
			4200,
			3000,
			20000,
			35000,
			50000,
			18000,
		},
		{
			// snip...
		},
	}
	p, err := charts.RadarRender(
		values,
		charts.TitleTextOptionFunc("Basic Radar Chart"),
		charts.LegendLabelsOptionFunc([]string{
			"Allocated Budget",
			"Actual Spending",
		}),
		charts.RadarIndicatorOptionFunc([]string{
			"Sales",
			"Administration",
			"Information Technology",
			"Customer Support",
			"Development",
			"Marketing",
		}, []float64{
			6500,
			16000,
			30000,
			38000,
			52000,
			25000,
		}),
	)
	if err != nil {
		panic(err)
	}

	buf, err := p.Bytes()
	if err != nil {
		panic(err)
	}
	// snip...
}

Funnel Chart

package main

import (
	"github.com/vicanso/go-charts/v2"
)

func main() {
	values := []float64{
		100,
		80,
		60,
		40,
		20,
	}
	p, err := charts.FunnelRender(
		values,
		charts.TitleTextOptionFunc("Funnel"),
		charts.LegendLabelsOptionFunc([]string{
			"Show",
			"Click",
			"Visit",
			"Inquiry",
			"Order",
		}),
	)
	if err != nil {
		panic(err)
	}

	buf, err := p.Bytes()
	if err != nil {
		panic(err)
	}
	// snip...
}

Table

package main

import (
	"github.com/vicanso/go-charts/v2"
)

func main() {
	header := []string{
		"Name",
		"Age",
		"Address",
		"Tag",
		"Action",
	}
	data := [][]string{
		{
			"John Brown",
			"32",
			"New York No. 1 Lake Park",
			"nice, developer",
			"Send Mail",
		},
		{
			"Jim Green	",
			"42",
			"London No. 1 Lake Park",
			"wow",
			"Send Mail",
		},
		{
			"Joe Black	",
			"32",
			"Sidney No. 1 Lake Park",
			"cool, teacher",
			"Send Mail",
		},
	}
	spans := map[int]int{
		0: 2,
		1: 1,
		// 设置第三列的span
		2: 3,
		3: 2,
		4: 2,
	}
	p, err := charts.TableRender(
		header,
		data,
		spans,
	)
	if err != nil {
		panic(err)
	}

	buf, err := p.Bytes()
	if err != nil {
		panic(err)
	}
	// snip...
}

ECharts Render

package main

import (
	"github.com/vicanso/go-charts/v2"
)

func main() {
	buf, err := charts.RenderEChartsToPNG(`{
		"title": {
			"text": "Line"
		},
		"xAxis": {
			"data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
		},
		"series": [
			{
				"data": [150, 230, 224, 218, 135, 147, 260]
			}
		]
	}`)
	// snip...
}

ECharts Option

The name with [] is new parameter, others are the same as echarts.

  • [type] The canvas type, support svg and png, default is svg
  • [theme] The theme, support dark, light and grafana, default is light
  • [fontFamily] The font family for chart
  • [padding] The padding of chart
  • [box] The canvas box of chart
  • [width] The width of chart
  • [height] The height of chart
  • title Title component, including main title and subtitle
    • title.text The main title text, supporting for \n for newlines
    • title.subtextSubtitle text, supporting for \n for newlines
    • title.left Distance between title component and the left side of the container. Left value can be instant pixel value like 20; it can also be a percentage value relative to container width like '20%'; and it can also be 'left', 'center', or 'right'.
    • title.top Distance between title component and the top side of the container. Top value can be instant pixel value like 20
    • title.textStyle.color Text color for title
    • title.textStyle.fontSize Text font size for title
    • title.textStyle.fontFamily Text font family for title, it will change the font family for chart
  • xAxis The x axis in cartesian(rectangular) coordinate. go-charts only support one x axis.
    • xAxis.boundaryGap The boundary gap on both sides of a coordinate axis. The setting and behavior of category axes and non-category axes are different. If set null or true, the label appear in the center part of two axis ticks.
    • xAxis.splitNumber Number of segments that the axis is split into. Note that this number serves only as a recommendation, and the true segments may be adjusted based on readability
    • xAxis.data Category data, only support string array.
  • yAxis The y axis in cartesian(rectangular) coordinate, it support 2 y axis
    • yAxis.min The minimum value of axis. It will be automatically computed to make sure axis tick is equally distributed when not set
    • yAxis.max The maximum value of axis. It will be automatically computed to make sure axis tick is equally distributed when not se.
    • yAxis.axisLabel.formatter Formatter of axis label, which supports string template: "formatter": "{value} kg"
    • yAxis.axisLine.lineStyle.color The color for line
  • legend Legend component
    • legend.show Whether to show legend
    • legend.data Data array of legend, only support string array: ["Email", "Video Ads"]
    • legend.align Legend marker and text aligning. Support left and right, default is left
    • legend.padding legend space around content
    • legend.left Distance between legend component and the left side of the container. Left value can be instant pixel value like 20; it can also be a percentage value relative to container width like '20%'; and it can also be 'left', 'center', or 'right'.
    • legend.top Distance between legend component and the top side of the container. Top value can be instant pixel value like 20
  • radar Coordinate for radar charts
    • radar.indicator Indicator of radar chart, which is used to assign multiple variables(dimensions) in radar chart
      • radar.indicator.name Indicator's name
      • radar.indicator.max The maximum value of indicator
      • radar.indicator.min The minimum value of indicator, default value is 0.
  • series The series for chart
    • series.name Series name used for displaying in legend.
    • series.type Series type: line, bar, pie, radar or funnel
    • series.radius Radius of Pie chart:50%, default is 40%
    • series.yAxisIndex Index of y axis to combine with, which is useful for multiple y axes in one chart
    • series.label.show Whether to show label
    • series.label.distance Distance to the host graphic element
    • series.label.color Label color
    • series.itemStyle.color Color for the series's item
    • series.markPoint Mark point in a chart.
    • series.markPoint.symbolSize Symbol size, default is 30
    • series.markPoint.data Data array for mark points, each of which is an object and the type only support max and min: [{"type": "max"}, {"type": "min"}]
    • series.markLine Mark line in a chart
    • series.markPoint.data Data array for mark points, each of which is an object and the type only support max, min and average: `[{"type": "max"}, {"type": "min"}, {"type": "average"}]``
    • series.data Data array of series, which can be in the following forms:
      • value It's a float array: [1.1, 2,3, 5.2]
      • object It's a object value array: [{"value": 1048, "name": "Search Engine"},{"value": 735,"name": "Direct"}]
  • [children] The options of children chart

Performance

Generate a png chart will be less than 20ms. It's better than using chrome headless with echarts.

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

More Repositories

1

diving

Exploring each layer in a docker image
JavaScript
259
star
2

pike

HTTP cache server, such as varnish
JavaScript
168
star
3

cyberapi

API tool based on tauri, it is smaller and faster.
Rust
151
star
4

articles

my articles
JavaScript
99
star
5

influxdb-nodejs

Simple influxdb client
JavaScript
85
star
6

async-local-storage

local storage that is shared between all stack frames (top down) in a call chain, including async function
JavaScript
73
star
7

tiny-site

图片优化
Go
72
star
8

elton

High performance, simple Go web framework
Go
61
star
9

go-axios

HTTP Request package for golang.
Go
45
star
10

cyber-tect

checker for tcp udp and http
Go
26
star
11

tiny

compress data for better performance
Go
21
star
12

npm-trend

Get the trend of npm
JavaScript
17
star
13

proxy-pool

http(s) proxy pool
Go
16
star
14

jtstats

statistics server
JavaScript
11
star
15

location

Go
10
star
16

varnish-agent

让varnish更简单
Go
9
star
17

influx-ql

Simple way for influx ql
JavaScript
9
star
18

koa-log

logger middlware for koa
JavaScript
9
star
19

base

jquery ui
CoffeeScript
8
star
20

go-stringify

golang stringify function like javascript
Go
7
star
21

superagent-load-balancer

load balacner plugin for superagent
JavaScript
6
star
22

performance-nodejs

get nodejs performance, such as: heap statistics, event loop delay
JavaScript
6
star
23

dcharts

A powerful charting and visualization library is based on d3
JavaScript
6
star
24

forest

web framework by elton
Go
6
star
25

go-cache

lru and redis cache
Go
6
star
26

nano-seconds

Get the nano seconds of current time
JavaScript
5
star
27

jtdashboard

jtstats dashboard
JavaScript
4
star
28

promise-memorize

Generate function for cache promise result
JavaScript
4
star
29

koa-rest-version

koa rest version parser
JavaScript
4
star
30

varnish-generator

The simple way of generating general vcl file for varnish
JavaScript
4
star
31

web-screenshot

screenshot of web
Go
3
star
32

lru-store

A lru store for browser
JavaScript
3
star
33

superjson

json picker and converter
Go
3
star
34

session

simple session
Go
2
star
35

supervisor

backend supervisor
JavaScript
2
star
36

elite-server

Go
2
star
37

consul-client

consul client
JavaScript
2
star
38

lru-ttl

lru cache with ttl
Go
2
star
39

jtui

jquery ui backbone
CoffeeScript
2
star
40

haproxy-agent

generate haproxy config
JavaScript
2
star
41

jtfileimporter

import css js file
JavaScript
2
star
42

dockerfiles

my docker file
VCL
2
star
43

upstream

proxy upstream
Go
2
star
44

koa-simple-session

koa 2.x session store with file, redis or others.
JavaScript
2
star
45

superagent-extend

extend superagent
JavaScript
2
star
46

aslant

graphing and visualization application for influxdb
JavaScript
2
star
47

image-pipeline-server

Go
2
star
48

elton-proxy

Proxy middleware for elton.
Go
2
star
49

awesome-go

It's a mirror of `avelino/awesome-go`, which sorts the repos by stars, while original `awesome-go` sorts by alphabet only.
Go
2
star
50

jtstatic

node static
JavaScript
2
star
51

albi

Web framework base on koa 2.x
JavaScript
2
star
52

elton-session

Session middleware for elton, it supports multi storage.
Go
2
star
53

jtprocfs-stats

系统性能监控
JavaScript
2
star
54

dnscache

dns cache
Go
2
star
55

wsl

卫斯理小说
Go
2
star
56

static

serve static file for http
Go
2
star
57

diving-rs

Exploring each layer in a docker image, it's fast and simple
Rust
2
star
58

timtam-logger

log for node.js
JavaScript
2
star
59

koa-http-stats

http stats middleware for koa
JavaScript
1
star
60

aslant.site

The source of aslant.site
HTML
1
star
61

spt

koa framework
JavaScript
1
star
62

jtstats_client

stats client
HTML
1
star
63

mongostat-influxdb

Get mongo stat and insert into influxdb
JavaScript
1
star
64

go-performance

performance of application, include cpu, memory usage, and etc.
Go
1
star
65

dns-server

dns server
JavaScript
1
star
66

nginx-alpine

The nginx docker
Dockerfile
1
star
67

koa-connection-limit

koa middleware
JavaScript
1
star
68

compression-performance

Go
1
star
69

jtstats_server

statistics server
JavaScript
1
star
70

cookies

Signed and unsigned cookies based on Keygrip
Go
1
star
71

jtlog_analyze

log analyze
JavaScript
1
star
72

varnish-alpine

Varnish docker image base on alpine
VCL
1
star
73

viperx

extend viper
Go
1
star
74

coredns-admin

admin for coredns
JavaScript
1
star
75

alarms

my alarms server
Go
1
star
76

jtcluster

node cluster
JavaScript
1
star
77

go-haproxy-agent

Go
1
star
78

mongoose-save4update

JavaScript
1
star
79

kit

vue framework
CSS
1
star
80

ips

Check ip is exists in iplist
Go
1
star
81

tiny-client

tiny cli client
Go
1
star
82

shadow

Go
1
star
83

code-identifier

stateless code identifier
JavaScript
1
star
84

supertiming

function timing
JavaScript
1
star
85

x

my open source projects
1
star
86

koa_base

koa base
1
star
87

superlocation

get mobile location
JavaScript
1
star
88

timtam

JavaScript
1
star
89

wsl-web

卫斯理小说网页
1
star
90

image-optim

Rust
1
star
91

hes

custom errors
Go
1
star
92

count-warner

count warner, when the count greater than limit, it will tigger a warn event
Go
1
star
93

warner

If meet the required criterion, it will trigger an event.
JavaScript
1
star
94

vicanso.github.io

HTML
1
star
95

jtsys

system monitor
HTML
1
star
96

go-gauge

simple measure for sum and mean
Go
1
star
97

repos

my repositories
1
star
98

elton-logger

Go
1
star
99

novel-backend

JavaScript
1
star
100

koa-varnish

The cache middleware for koa, it can cache the data such as varnish.
JavaScript
1
star