charts

package module
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2022 License: MIT Imports: 15 Imported by: 0

README

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.

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

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

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.LineRender([][]float64{
		{
			150,
			230,
			224,
			218,
			135,
			147,
			260,
		},
	},
		// output type
		charts.PNGTypeOption(),
		// title
		charts.TitleOptionFunc(charts.TitleOption{
			Text: "Line",
		}),
		// x axis
		charts.XAxisOptionFunc(charts.NewXAxisOption([]string{
			"Mon",
			"Tue",
			"Wed",
			"Thu",
			"Fri",
			"Sat",
			"Sun",
		})),
	)
	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)
		}
	}
}

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

Documentation

Index

Constants

View Source
const (
	ChartTypeLine   = "line"
	ChartTypeBar    = "bar"
	ChartTypePie    = "pie"
	ChartTypeRadar  = "radar"
	ChartTypeFunnel = "funnel"
)
View Source
const (
	ChartOutputSVG = "svg"
	ChartOutputPNG = "png"
)
View Source
const (
	PositionLeft   = "left"
	PositionRight  = "right"
	PositionCenter = "center"
	PositionTop    = "top"
	PositionBottom = "bottom"
)
View Source
const (
	OrientHorizontal = "horizontal"
	OrientVertical   = "vertical"
)
View Source
const (
	SeriesMarkDataTypeMax     = "max"
	SeriesMarkDataTypeMin     = "min"
	SeriesMarkDataTypeAverage = "average"
)
View Source
const (
	LegendIconRect = "rect"
)
View Source
const ThemeAnt = "ant"
View Source
const ThemeDark = "dark"
View Source
const ThemeGrafana = "grafana"
View Source
const ThemeLight = "light"
View Source
const YAxisWidth = 40

TODO 长度是否可以变化

Variables

View Source
var ErrFontNotExists = errors.New("font is not exists")
View Source
var ErrTableColumnWidthInvalid = errors.New("table column width is invalid")

Functions

func AddTheme added in v1.0.0

func AddTheme(name string, isDarkMode bool, axisStrokeColor, axisSplitLineColor, backgroundColor, textColor drawing.Color, seriesColors []drawing.Color)

func FalseFlag added in v1.0.0

func FalseFlag() *bool

func GetFont added in v0.0.3

func GetFont(fontFamily string) (*truetype.Font, error)

GetFont get the font by font family

func InstallFont added in v0.0.3

func InstallFont(fontFamily string, data []byte) error

InstallFont installs the font for charts

func NewAxis added in v1.0.0

func NewAxis(d *Draw, data AxisDataList, option AxisOption) *axis

NewAxis creates a new axis with data and style options

func NewFloatPoint added in v1.0.0

func NewFloatPoint(f float64) *float64

func NewLegend added in v1.0.0

func NewLegend(d *Draw, opt LegendOption) *legend

func RenderEChartsToPNG

func RenderEChartsToPNG(options string) ([]byte, error)

func RenderEChartsToSVG

func RenderEChartsToSVG(options string) ([]byte, error)

func SetDefaultHeight added in v1.0.0

func SetDefaultHeight(height int)

func SetDefaultWidth added in v1.0.0

func SetDefaultWidth(width int)

func TableMeasure added in v1.2.2

func TableMeasure(opt TableOption) (chart.Box, error)

func TrueFlag added in v1.0.0

func TrueFlag() *bool

Types

type AxisData added in v1.0.0

type AxisData struct {
	// The text value of axis
	Text string
}

type AxisDataList added in v1.0.0

type AxisDataList []AxisData

func NewAxisDataListFromStringList added in v1.0.0

func NewAxisDataListFromStringList(textList []string) AxisDataList

NewAxisDataListFromStringList creates a new axis data list from string list

func (AxisDataList) TextList added in v1.0.0

func (l AxisDataList) TextList() []string

TextList returns the text list of axis data

type AxisOption added in v1.0.0

type AxisOption struct {
	// The boundary gap on both sides of a coordinate axis.
	// Nil or *true means the center part of two axis ticks
	BoundaryGap *bool
	// The flag for show axis, set this to *false will hide axis
	Show *bool
	// The position of axis, it can be 'left', 'top', 'right' or 'bottom'
	Position string
	// Number of segments that the axis is split into. Note that this number serves only as a recommendation.
	SplitNumber int
	ClassName   string
	// The line color of axis
	StrokeColor drawing.Color
	// The line width
	StrokeWidth float64
	// The length of the axis tick
	TickLength int
	// The flag for show axis tick, set this to *false will hide axis tick
	TickShow *bool
	// The margin value of label
	LabelMargin int
	// The font size of label
	FontSize float64
	// The font of label
	Font *truetype.Font
	// The color of label
	FontColor drawing.Color
	// The flag for show axis split line, set this to true will show axis split line
	SplitLineShow bool
	// The color of split line
	SplitLineColor drawing.Color
}

func (*AxisOption) GetLabelMargin added in v1.0.0

func (as *AxisOption) GetLabelMargin() int

GetLabelMargin returns the label margin value

func (*AxisOption) GetTickLength added in v1.0.0

func (as *AxisOption) GetTickLength() int

GetTickLength returns the tick length value

func (*AxisOption) Style added in v1.0.0

func (as *AxisOption) Style(f *truetype.Font) chart.Style

Style returns the style of axis

type BarStyle added in v1.0.0

type BarStyle struct {
	ClassName       string
	StrokeDashArray []float64
	FillColor       drawing.Color
}

func (*BarStyle) Style added in v1.0.0

func (bs *BarStyle) Style() chart.Style

type ChartOption added in v1.0.0

type ChartOption struct {
	// The output type of chart, "svg" or "png", default value is "svg"
	Type string
	// The font family, which should be installed first
	FontFamily string
	// The font of chart, the default font is "roboto"
	Font *truetype.Font
	// The theme of chart, "light" and "dark".
	// The default theme is "light"
	Theme string
	// The title option
	Title TitleOption
	// The legend option
	Legend LegendOption
	// The x axis option
	XAxis XAxisOption
	// The y axis option list
	YAxisList []YAxisOption
	// The width of chart, default width is 600
	Width int
	// The height of chart, default height is 400
	Height int
	Parent *Draw
	// The padding for chart, default padding is [20, 10, 10, 10]
	Padding chart.Box
	// The canvas box for chart
	Box chart.Box
	// The series list
	SeriesList SeriesList
	// The radar indicator list
	RadarIndicators []RadarIndicator
	// The background color of chart
	BackgroundColor drawing.Color
	// The child charts
	Children []ChartOption
}

func (*ChartOption) FillDefault added in v1.0.0

func (o *ChartOption) FillDefault(theme string)

FillDefault fills the default value for chart option

type Draw added in v1.0.0

type Draw struct {
	// Render
	Render chart.Renderer
	// The canvas box
	Box chart.Box
	// The font for draw
	Font *truetype.Font
	// contains filtered or unexported fields
}

func BarRender added in v1.2.0

func BarRender(values [][]float64, opts ...OptionFunc) (*Draw, error)

BarRender bar chart render

func FunnelRender added in v1.2.0

func FunnelRender(values []float64, opts ...OptionFunc) (*Draw, error)

FunnelRender funnel chart render

func LineRender added in v1.2.0

func LineRender(values [][]float64, opts ...OptionFunc) (*Draw, error)

LineRender line chart render

func NewDraw added in v1.0.0

func NewDraw(opt DrawOption, opts ...Option) (*Draw, error)

NewDraw returns a new draw canvas

func PieRender added in v1.2.0

func PieRender(values []float64, opts ...OptionFunc) (*Draw, error)

PieRender pie chart render

func RadarRender added in v1.2.0

func RadarRender(values [][]float64, opts ...OptionFunc) (*Draw, error)

RadarRender radar chart render

func Render added in v1.0.0

func Render(opt ChartOption, optFuncs ...OptionFunc) (*Draw, error)

Render renders the chart by option

func (*Draw) Bar added in v1.0.0

func (d *Draw) Bar(b chart.Box, style BarStyle)

Bar renders bar for chart

func (*Draw) Bytes added in v1.0.0

func (d *Draw) Bytes() ([]byte, error)

Bytes returns the data of draw canvas

func (*Draw) Line added in v1.0.0

func (d *Draw) Line(points []Point, style LineStyle)

func (*Draw) Parent added in v1.0.0

func (d *Draw) Parent() *Draw

Parent returns the parent of draw

func (*Draw) Top added in v1.0.0

func (d *Draw) Top() *Draw

Top returns the top parent of draw

type DrawOption added in v1.0.0

type DrawOption struct {
	// Draw type, "svg" or "png", default type is "svg"
	Type string
	// Parent of draw
	Parent *Draw
	// The width of draw canvas
	Width int
	// The height of draw canvas
	Height int
}

type EChartStyle

type EChartStyle struct {
	Color string `json:"color"`
}

func (*EChartStyle) ToStyle added in v1.0.0

func (es *EChartStyle) ToStyle() chart.Style

type EChartsAxisLabel added in v1.0.0

type EChartsAxisLabel struct {
	Formatter string `json:"formatter"`
}

type EChartsLabelOption added in v0.0.4

type EChartsLabelOption struct {
	Show     bool   `json:"show"`
	Distance int    `json:"distance"`
	Color    string `json:"color"`
}

type EChartsLegend added in v1.0.0

type EChartsLegend struct {
	Show      *bool            `json:"show"`
	Data      []string         `json:"data"`
	Align     string           `json:"align"`
	Orient    string           `json:"orient"`
	Padding   EChartsPadding   `json:"padding"`
	Left      EChartsPosition  `json:"left"`
	Top       EChartsPosition  `json:"top"`
	TextStyle EChartsTextStyle `json:"textStyle"`
}

type EChartsMarkData added in v1.0.0

type EChartsMarkData struct {
	Type string `json:"type"`
}

func (*EChartsMarkData) UnmarshalJSON added in v1.0.0

func (emd *EChartsMarkData) UnmarshalJSON(data []byte) error

type EChartsMarkLine added in v1.0.0

type EChartsMarkLine struct {
	Data []EChartsMarkData `json:"data"`
}

func (*EChartsMarkLine) ToSeriesMarkLine added in v1.0.0

func (eml *EChartsMarkLine) ToSeriesMarkLine() SeriesMarkLine

type EChartsMarkPoint added in v1.0.0

type EChartsMarkPoint struct {
	SymbolSize int               `json:"symbolSize"`
	Data       []EChartsMarkData `json:"data"`
}

func (*EChartsMarkPoint) ToSeriesMarkPoint added in v1.0.0

func (emp *EChartsMarkPoint) ToSeriesMarkPoint() SeriesMarkPoint

type EChartsOption added in v1.0.0

type EChartsOption struct {
	Type       string         `json:"type"`
	Theme      string         `json:"theme"`
	FontFamily string         `json:"fontFamily"`
	Padding    EChartsPadding `json:"padding"`
	Box        chart.Box      `json:"box"`
	Width      int            `json:"width"`
	Height     int            `json:"height"`
	Title      struct {
		Text         string           `json:"text"`
		Subtext      string           `json:"subtext"`
		Left         EChartsPosition  `json:"left"`
		Top          EChartsPosition  `json:"top"`
		TextStyle    EChartsTextStyle `json:"textStyle"`
		SubtextStyle EChartsTextStyle `json:"subtextStyle"`
	} `json:"title"`
	XAxis  EChartsXAxis  `json:"xAxis"`
	YAxis  EChartsYAxis  `json:"yAxis"`
	Legend EChartsLegend `json:"legend"`
	Radar  struct {
		Indicator []RadarIndicator `json:"indicator"`
	} `json:"radar"`
	Series   EChartsSeriesList `json:"series"`
	Children []EChartsOption   `json:"children"`
}

func (*EChartsOption) ToOption added in v1.0.0

func (eo *EChartsOption) ToOption() ChartOption

type EChartsPadding

type EChartsPadding struct {
	Box chart.Box
}

func (*EChartsPadding) UnmarshalJSON

func (eb *EChartsPadding) UnmarshalJSON(data []byte) error

type EChartsPosition added in v1.0.0

type EChartsPosition string

func (*EChartsPosition) UnmarshalJSON added in v1.0.0

func (p *EChartsPosition) UnmarshalJSON(data []byte) error

type EChartsSeries added in v1.0.0

type EChartsSeries struct {
	Data       []EChartsSeriesData `json:"data"`
	Name       string              `json:"name"`
	Type       string              `json:"type"`
	Radius     string              `json:"radius"`
	YAxisIndex int                 `json:"yAxisIndex"`
	ItemStyle  EChartStyle         `json:"itemStyle"`
	// label的配置
	Label     EChartsLabelOption `json:"label"`
	MarkPoint EChartsMarkPoint   `json:"markPoint"`
	MarkLine  EChartsMarkLine    `json:"markLine"`
	Max       *float64           `json:"max"`
	Min       *float64           `json:"min"`
}

type EChartsSeriesData added in v1.0.0

type EChartsSeriesData struct {
	Value     EChartsSeriesDataValue `json:"value"`
	Name      string                 `json:"name"`
	ItemStyle EChartStyle            `json:"itemStyle"`
}

func (*EChartsSeriesData) UnmarshalJSON added in v1.0.0

func (es *EChartsSeriesData) UnmarshalJSON(data []byte) error

type EChartsSeriesDataValue added in v1.1.0

type EChartsSeriesDataValue struct {
	// contains filtered or unexported fields
}

func NewEChartsSeriesDataValue added in v1.1.0

func NewEChartsSeriesDataValue(values ...float64) EChartsSeriesDataValue

func (*EChartsSeriesDataValue) First added in v1.1.0

func (value *EChartsSeriesDataValue) First() float64

func (*EChartsSeriesDataValue) UnmarshalJSON added in v1.1.0

func (value *EChartsSeriesDataValue) UnmarshalJSON(data []byte) error

type EChartsSeriesList added in v1.0.0

type EChartsSeriesList []EChartsSeries

func (EChartsSeriesList) ToSeriesList added in v1.0.0

func (esList EChartsSeriesList) ToSeriesList() SeriesList

type EChartsTextStyle added in v1.0.0

type EChartsTextStyle struct {
	Color      string  `json:"color"`
	FontFamily string  `json:"fontFamily"`
	FontSize   float64 `json:"fontSize"`
}

func (*EChartsTextStyle) ToStyle added in v1.0.0

func (et *EChartsTextStyle) ToStyle() chart.Style

type EChartsXAxis

type EChartsXAxis struct {
	Data []EChartsXAxisData
}

func (*EChartsXAxis) UnmarshalJSON

func (ex *EChartsXAxis) UnmarshalJSON(data []byte) error

type EChartsXAxisData added in v1.0.0

type EChartsXAxisData struct {
	BoundaryGap *bool    `json:"boundaryGap"`
	SplitNumber int      `json:"splitNumber"`
	Data        []string `json:"data"`
}

type EChartsYAxis

type EChartsYAxis struct {
	Data []EChartsYAxisData `json:"data"`
}

func (*EChartsYAxis) UnmarshalJSON

func (ey *EChartsYAxis) UnmarshalJSON(data []byte) error

type EChartsYAxisData added in v1.0.0

type EChartsYAxisData struct {
	Min       *float64         `json:"min"`
	Max       *float64         `json:"max"`
	AxisLabel EChartsAxisLabel `json:"axisLabel"`
	AxisLine  struct {
		LineStyle struct {
			Color string `json:"color"`
		} `json:"lineStyle"`
	} `json:"axisLine"`
}

type LabelFormatter added in v1.0.0

type LabelFormatter func(index int, value float64, percent float64) string

func NewLabelFormatter added in v1.0.0

func NewLabelFormatter(seriesNames []string, layout string) LabelFormatter

func NewPieLabelFormatter added in v1.0.0

func NewPieLabelFormatter(seriesNames []string, layout string) LabelFormatter

func NewValueLabelFormater added in v1.0.0

func NewValueLabelFormater(seriesNames []string, layout string) LabelFormatter

type LegendOption

type LegendOption struct {

	// Legend show flag, if nil or true, the legend will be shown
	Show *bool
	// Legend text style
	Style chart.Style
	// Text array of legend
	Data []string
	// Distance between legend component and the left side of the container.
	// It can be pixel value: 20, percentage value: 20%,
	// or position value: right, center.
	Left string
	// Distance between legend component and the top side of the container.
	// It can be pixel value: 20.
	Top string
	// Legend marker and text aligning, it can be left or right, default is left.
	Align string
	// The layout orientation of legend, it can be horizontal or vertical, default is horizontal.
	Orient string
	// Icon of the legend.
	Icon string
	// contains filtered or unexported fields
}

func NewLegendOption added in v1.0.0

func NewLegendOption(data []string, position ...string) LegendOption

NewLegendOption creates a new legend option by legend text list

type LineStyle added in v1.0.0

type LineStyle struct {
	ClassName       string
	StrokeDashArray []float64
	StrokeColor     drawing.Color
	StrokeWidth     float64
	FillColor       drawing.Color
	DotWidth        float64
	DotColor        drawing.Color
	DotFillColor    drawing.Color
}

func (*LineStyle) Style added in v1.0.0

func (ls *LineStyle) Style() chart.Style

type Option added in v1.0.0

type Option func(*Draw) error

func BoxOption added in v1.0.0

func BoxOption(box chart.Box) Option

BoxOption set the box of draw canvas

func PaddingOption added in v1.0.0

func PaddingOption(padding chart.Box) Option

PaddingOption sets the padding of draw canvas

type OptionFunc added in v1.2.0

type OptionFunc func(opt *ChartOption)

OptionFunc option function

func BackgroundColorOptionFunc added in v1.2.0

func BackgroundColorOptionFunc(color drawing.Color) OptionFunc

BackgroundColorOptionFunc set background color of chart

func BoxOptionFunc added in v1.2.0

func BoxOptionFunc(box chart.Box) OptionFunc

BoxOptionFunc set box of chart

func ChildOptionFunc added in v1.2.0

func ChildOptionFunc(child ...ChartOption) OptionFunc

ChildOptionFunc add child chart

func FontFamilyOptionFunc added in v1.2.0

func FontFamilyOptionFunc(fontFamily string) OptionFunc

FontFamilyOptionFunc set font family of chart

func HeightOptionFunc added in v1.2.0

func HeightOptionFunc(height int) OptionFunc

HeightOptionFunc set height of chart

func LegendOptionFunc added in v1.2.0

func LegendOptionFunc(legend LegendOption) OptionFunc

LegendOptionFunc set legend of chart

func PNGTypeOption added in v1.2.0

func PNGTypeOption() OptionFunc

PNGTypeOption set png type of chart's output

func PaddingOptionFunc added in v1.2.0

func PaddingOptionFunc(padding chart.Box) OptionFunc

PaddingOptionFunc set padding of chart

func RadarIndicatorOptionFunc added in v1.2.0

func RadarIndicatorOptionFunc(radarIndicator ...RadarIndicator) OptionFunc

RadarIndicatorOptionFunc set radar indicator of chart

func ThemeOptionFunc added in v1.2.0

func ThemeOptionFunc(theme string) OptionFunc

ThemeOptionFunc set them of chart

func TitleOptionFunc added in v1.2.0

func TitleOptionFunc(title TitleOption) OptionFunc

TitleOptionFunc set title of chart

func TypeOptionFunc added in v1.2.0

func TypeOptionFunc(t string) OptionFunc

TypeOptionFunc set type of chart's output

func WidthOptionFunc added in v1.2.0

func WidthOptionFunc(width int) OptionFunc

WidthOptionFunc set width of chart

func XAxisOptionFunc added in v1.2.0

func XAxisOptionFunc(xAxisOption XAxisOption) OptionFunc

XAxisOptionFunc set x axis of chart

func YAxisOptionFunc added in v1.2.0

func YAxisOptionFunc(yAxisOption ...YAxisOption) OptionFunc

YAxisOptionFunc set y axis of chart, support two y axis

type PieSeriesOption added in v1.0.0

type PieSeriesOption struct {
	Radius string
	Label  SeriesLabel
	Names  []string
}

type Point added in v1.0.0

type Point struct {
	X int
	Y int
}

type RadarIndicator added in v1.1.0

type RadarIndicator struct {
	// Indicator's name
	Name string
	// The maximum value of indicator
	Max float64
	// The minimum value of indicator
	Min float64
}

type Range

type Range struct {
	Min      float64
	Max      float64
	Size     int
	Boundary bool
	// contains filtered or unexported fields
}

func NewRange added in v1.0.0

func NewRange(min, max float64, divideCount int) Range

func (*Range) AutoDivide added in v1.0.0

func (r *Range) AutoDivide() []int

func (*Range) GetRange added in v1.0.0

func (r *Range) GetRange(index int) (float64, float64)

func (Range) Values added in v1.0.0

func (r Range) Values() []string

type Series

type Series struct {

	// The type of series, it can be "line", "bar" or "pie".
	// Default value is "line"
	Type string
	// The data list of series
	Data []SeriesData
	// The Y axis index, it should be 0 or 1.
	// Default value is 1
	YAxisIndex int
	// The style for series
	Style chart.Style
	// The label for series
	Label SeriesLabel
	// The name of series
	Name string
	// Radius for Pie chart, e.g.: 40%, default is "40%"
	Radius string
	// Mark point for series
	MarkPoint SeriesMarkPoint
	// Make line for series
	MarkLine SeriesMarkLine
	// Max value of series
	Min *float64
	// Min value of series
	Max *float64
	// contains filtered or unexported fields
}

func NewSeriesFromValues added in v1.0.0

func NewSeriesFromValues(values []float64, chartType ...string) Series

func (*Series) Summary added in v1.0.0

func (s *Series) Summary() seriesSummary

type SeriesData

type SeriesData struct {
	// The value of series data
	Value float64
	// The style of series data
	Style chart.Style
}

func NewSeriesDataFromValues added in v1.0.0

func NewSeriesDataFromValues(values []float64) []SeriesData

type SeriesLabel added in v0.0.4

type SeriesLabel struct {
	// Data label formatter, which supports string template.
	// {b}: the name of a data item.
	// {c}: the value of a data item.
	// {d}: the percent of a data item(pie chart).
	Formatter string
	// The color for label
	Color drawing.Color
	// Show flag for label
	Show bool
	// Distance to the host graphic element.
	Distance int
}

type SeriesList added in v1.0.0

type SeriesList []Series

func NewPieSeriesList added in v1.0.0

func NewPieSeriesList(values []float64, opts ...PieSeriesOption) SeriesList

func (SeriesList) Names added in v1.0.0

func (sl SeriesList) Names() []string

type SeriesMarkData added in v1.0.0

type SeriesMarkData struct {
	// The mark data type, it can be "max", "min", "average".
	// The "average" is only for mark line
	Type string
}

type SeriesMarkLine added in v1.0.0

type SeriesMarkLine struct {
	// The mark data of series mark line
	Data []SeriesMarkData
}

func NewMarkLine added in v1.0.0

func NewMarkLine(markLineTypes ...string) SeriesMarkLine

type SeriesMarkPoint added in v1.0.0

type SeriesMarkPoint struct {
	// The width of symbol, default value is 30
	SymbolSize int
	// The mark data of series mark point
	Data []SeriesMarkData
}

func NewMarkPoint added in v1.0.0

func NewMarkPoint(markPointTypes ...string) SeriesMarkPoint

type TableOption added in v1.2.2

type TableOption struct {
	// draw
	Draw *Draw
	// The width of table
	Width int
	// The header of table
	Header []string
	// The style of table
	Style        chart.Style
	ColumnWidths []float64
	// contains filtered or unexported fields
}

type Theme added in v1.0.0

type Theme struct {
	// contains filtered or unexported fields
}

func NewTheme added in v1.0.0

func NewTheme(name string) *Theme

func (*Theme) GetAxisSplitLineColor added in v1.0.0

func (t *Theme) GetAxisSplitLineColor() drawing.Color

func (*Theme) GetAxisStrokeColor added in v1.0.0

func (t *Theme) GetAxisStrokeColor() drawing.Color

func (*Theme) GetBackgroundColor added in v1.0.0

func (t *Theme) GetBackgroundColor() drawing.Color

func (*Theme) GetSeriesColor added in v1.0.0

func (t *Theme) GetSeriesColor(index int) drawing.Color

func (*Theme) GetTextColor added in v1.0.0

func (t *Theme) GetTextColor() drawing.Color

func (*Theme) IsDark added in v1.0.0

func (t *Theme) IsDark() bool

type TitleOption added in v1.0.0

type TitleOption struct {
	// Title text, support \n for new line
	Text string
	// Subtitle text, support \n for new line
	Subtext string
	// Title style
	Style chart.Style
	// Subtitle style
	SubtextStyle chart.Style
	// Distance between title component and the left side of the container.
	// It can be pixel value: 20, percentage value: 20%,
	// or position value: right, center.
	Left string
	// Distance between title component and the top side of the container.
	// It can be pixel value: 20.
	Top string
}

type XAxisOption added in v1.0.0

type XAxisOption struct {
	Font *truetype.Font
	// The boundary gap on both sides of a coordinate axis.
	// Nil or *true means the center part of two axis ticks
	BoundaryGap *bool
	// The data value of x axis
	Data []string
	// The theme of chart
	Theme string
	// Hidden x axis
	Hidden bool
	// Number of segments that the axis is split into. Note that this number serves only as a recommendation.
	SplitNumber int
}

func NewXAxisOption added in v1.0.0

func NewXAxisOption(data []string, boundaryGap ...*bool) XAxisOption

type YAxisOption

type YAxisOption struct {
	// The minimun value of axis.
	Min *float64
	// The maximum value of axis.
	Max *float64
	// Hidden y axis
	Hidden bool
	// Formatter for y axis text value
	Formatter string
	// Color for y axis
	Color drawing.Color
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL