Categorygithub.com/go-analyze/charts
modulepackage
0.3.0
Repository: https://github.com/go-analyze/charts.git
Documentation: pkg.go.dev

# README

go-analyze/charts

license Build Status

go-analyze/charts is a fork from vicanso/go-charts and wcharczuk/go-chart. Our library focuses on simplifying the generation of beautiful charts and graphs.

Current Project Status

Leveraging the strengths of vicanso/go-charts and wcharczuk/go-chart, our project introduces enhancements for rendering under challenging conditions and expands functionality with minimal setup. We aim to build upon their solid foundation to offer a more versatile and user-friendly charting solution.

API Stability

We're committed to refining the API, incorporating feedback and new ideas to enhance flexibility and ease of use.

Until the v1.0.0 release, API changes should be anticipated. If you require a library with minimal user facing changes this project has not yet reached that level of maturity.

Changes

Notable improvements in our fork include:

  • Axis Improvements: Significant enhancements to axis rendering, data range selection, and configuration simplification were made in PR #3.
  • Theming: In PR #4 (and some subsequent changes) we introduced vivid-light and vivid-dark themes for more vibrant visualizations, alongside API changes for greater theme and font control. Long term we plan to make themes easier to mutate and define.
  • Configuration Simplification: PR #5 began our effort to streamline chart configuration, making names more descriptive and specific while focusing on a theme-centric approach. Documentation on configuration and use is also being improved. (See also #15, #20)
  • Expanded Testing: Ongoing test coverage expansions have led to bug discoveries and fixes. This will continue to help ensure that our charts render perfectly for a wide range of configurations and use.

Our library is a work in progress, aiming to become a standout choice for Go developers seeking powerful, yet easy-to-use charting tools. We welcome contributions and feedback as we continue to enhance our library's functionality, configurability, and reliability.

wcharczuk/go-chart Changes

If you are a former user of wcharczuk/go-chart, you should be able to use this project with reasonable changes. The wcharczuk/go-chart project was forked under our chartdraw package. Since that inclusion we have made the following API changes:

  • Font configuration has been moved out of Style, and instead requires the FontStyle struct to be initialized to define Font specifics. (see PR #15)

Functionality

Themes

Our built in themes are: light, dark, vivid-light, vivid-dark, ant, grafana

themes

Chart Types

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

Please see a variety of examples in the ./examples/ directory.

Line Chart

Line Chart
package main

import (
	"github.com/go-analyze/charts"
)

func main() {
	// values specified where the first index is for each data series or source, and the second index is for each sample.
	values := [][]float64{
		{
			120,
			132,
			101,
			134,
			90,
			230,
			210,
		},
		{
			// specify values for additional data series
		},
	}
	p, err := charts.LineRender(
		values,
		charts.TitleTextOptionFunc("Line"),
		charts.XAxisDataOptionFunc([]string{
			"Mon",	// notice the 7 labels here match to the 7 samples above
			"Tue",
			"Wed",
			"Thu",
			"Fri",
			"Sat",
			"Sun",
		}),
		charts.LegendLabelsOptionFunc([]string{
			"Email",
			"Search Engine",
		}),
	)
	// snip...
}

Bar Chart

Bar Chart
package main

import (
	"github.com/go-analyze/charts"
)

func main() {
	// values specified where the first index is for each data series or source, and the second index is for each sample.
	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.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,
			)
		},
	)
	// snip...
}

Horizontal Bar Chart

Horizontal Bar Chart
package main

import (
	"github.com/go-analyze/charts"
)

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",
		}),
	)
	// snip...
}

Pie Chart

Pie Chart
package main

import (
	"github.com/go-analyze/charts"
)

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",
			Offset:  charts.OffsetCenter,
		}),
		charts.PaddingOptionFunc(charts.Box{
			Top:    20,
			Right:  20,
			Bottom: 20,
			Left:   20,
		}),
		charts.LegendOptionFunc(charts.LegendOption{
			Veritcal: true,
			Data: []string{
				"Search Engine",
				"Direct",
				"Email",
				"Union Ads",
				"Video Ads",
			},
			Offset: charts.OffsetLeft,
		}),
		charts.PieSeriesShowLabel(),
	)
	// snip...	
}

Radar Chart

Radar Chart
package main

import (
	"github.com/go-analyze/charts"
)

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,
		}),
	)
	// snip...
}

Table

Table
package main

import (
	"github.com/go-analyze/charts"
)

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,
		2: 3,
		3: 2,
		4: 2,
	}
	p, err := charts.TableRender(
		header,
		data,
		spans,
	)
	// snip...
}

Funnel Chart

package main

import (
	"github.com/go-analyze/charts"
)

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",
		}),
	)
	// snip...
}

ECharts Render

package main

import (
	"github.com/go-analyze/charts"
)

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...
}

# Packages

No description provided by the author
No description provided by the author

# Functions

BarRender bar chart render.
BoolPointer returns a pointer to the given bool value, useful for configuration.
BoxOptionFunc set box of chart.
ChildOptionFunc add child chart.
False returns a pointer to a false bool, useful for configuration.
FloatPointer returns a pointer to the given float64 value, useful for configuration.
FontOptionFunc set font of chart.
FunnelRender funnel chart render.
GetDefaultFont get default font.
GetDefaultTheme returns the default theme.
GetFont get the font by font family or the default if the family is not installed.
GetNullValue gets the null value.
GetTheme returns an installed theme by name, or the default if the theme is not installed.
HeightOptionFunc set height of chart.
HorizontalBarRender horizontal bar chart render.
InstallFont installs the font for charts.
InstallTheme adds a theme to the catalog which can later be retrieved using GetTheme.
LegendLabelsOptionFunc set legend labels of chart.
LegendOptionFunc set legend of chart.
LineRender line chart render.
MakeTheme constructs a one-off theme without installing it into the catalog.
MarkLineOptionFunc set mark line for series of chart.
MarkPointOptionFunc set mark point for series of chart.
No description provided by the author
NewBarChart returns a bar chart renderer.
NewBottomXAxis returns a bottom x axis renderer.
No description provided by the author
NewFunnelChart returns a funnel chart renderer.
NewFunnelLabelFormatter returns a funner label formatter.
NewFunnelSeriesList returns a series list for funnel.
NewGridPainter returns new a grid renderer.
NewHorizontalBarChart returns a horizontal bar chart renderer.
NewLabelFormatter returns a label formatter.
NewLeftYAxis returns a left y axis renderer.
NewLegendPainter returns a legend renderer.
NewLineChart returns a line chart render.
NewMarkLine returns a series mark line.
NewMarkLinePainter returns a mark line renderer.
NewMarkPoint returns a series mark point.
NewMarkPointPainter returns a mark point renderer.
NewPainter creates a painter.
NewPieChart returns a pie chart renderer.
NewPieLabelFormatter returns a pie label formatter.
No description provided by the author
NewRadarChart returns a radar chart renderer.
NewRadarIndicators returns a radar indicator list.
NewRange returns a range of data for an axis, this range will have padding to better present the data.
NewRightYAxis returns a right y axis renderer.
No description provided by the author
NewSeriesDataFromValues return a series data.
NewSeriesFromValues returns a series.
No description provided by the author
NewSeriesListDataFromValues returns a series list.
NewTableChart returns a table chart render.
NewTitlePainter returns a title renderer.
NewValueLabelFormatter returns a value formatter.
OutputFormatOptionFunc set type of chart's output.
PaddingOptionFunc set padding of chart.
PainterBoxOption sets the box of draw painter.
PainterFontOption sets the font of draw painter.
PainterPaddingOption sets the padding of draw painter.
PainterStyleOption sets the style of draw painter.
PainterThemeOption sets the theme of draw painter.
PainterWidthHeightOption set width or height of draw painter.
PieRender pie chart render.
PieSeriesShowLabel set pie series show label.
PNGOutputOption set png type of chart's output.
RadarIndicatorOptionFunc set radar indicator of chart.
RadarRender radar chart render.
No description provided by the author
No description provided by the author
No description provided by the author
SetDefaultFont set default font by name.
SetDefaultHeight sets default height of chart.
SetDefaultTheme sets default theme by name.
SetDefaultWidth sets default width of chart.
SetNullValue sets the null value, default is MaxFloat64.
SVGOutputOption set svg type of chart's output.
TableOptionRender table render with option.
TableRender table chart render.
ThemeNameOptionFunc set them of chart by name.
ThemeOptionFunc set them of chart.
TitleOptionFunc set title of chart.
TitleTextOptionFunc set title text of chart.
True returns a pointer to a true bool, useful for configuration.
WidthOptionFunc set width of chart.
XAxisDataOptionFunc set x-axis data of chart.
XAxisOptionFunc set x-axis of chart.
YAxisDataOptionFunc set y-axis data of chart.
YAxisOptionFunc set y-axis of chart, supports up to two y-axis.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ThemeAnt is an ant styled theme.
ThemeDark is a dark alternative to the default theme 'light, with series colors from echarts'.
ThemeGrafana is a grafana styled theme.
ThemeLight is the default theme used, with series colors from echarts.
ThemeVividDark is a dark alternative to 'ThemeVividLight', with the same bright initial series colors.
ThemeVividLight is an alternative light theme that has red, yellow, and other bright colors initially in the series.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
OffsetInt provides an ability to configure a shift from the top or left alignments.
OffsetStr provides an ability to configure a shift from the top or left alignments using flexible string inputs.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
LabelFormatter label formatter.
OptionFunc option function.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author