Documentation ¶
Index ¶
- Constants
- Variables
- func AddTheme(name string, isDarkMode bool, ...)
- func FalseFlag() *bool
- func GetFont(fontFamily string) (*truetype.Font, error)
- func InstallFont(fontFamily string, data []byte) error
- func NewAxis(d *Draw, data AxisDataList, option AxisOption) *axis
- func NewFloatPoint(f float64) *float64
- func NewLegend(d *Draw, opt LegendOption) *legend
- func RenderEChartsToPNG(options string) ([]byte, error)
- func RenderEChartsToSVG(options string) ([]byte, error)
- func SetDefaultHeight(height int)
- func SetDefaultWidth(width int)
- func TableMeasure(opt TableOption) (chart.Box, error)
- func TrueFlag() *bool
- type AxisData
- type AxisDataList
- type AxisOption
- type BarStyle
- type ChartOption
- type Draw
- func BarRender(values [][]float64, opts ...OptionFunc) (*Draw, error)
- func FunnelRender(values []float64, opts ...OptionFunc) (*Draw, error)
- func LineRender(values [][]float64, opts ...OptionFunc) (*Draw, error)
- func NewDraw(opt DrawOption, opts ...Option) (*Draw, error)
- func PieRender(values []float64, opts ...OptionFunc) (*Draw, error)
- func RadarRender(values [][]float64, opts ...OptionFunc) (*Draw, error)
- func Render(opt ChartOption, optFuncs ...OptionFunc) (*Draw, error)
- type DrawOption
- type EChartStyle
- type EChartsAxisLabel
- type EChartsLabelOption
- type EChartsLegend
- type EChartsMarkData
- type EChartsMarkLine
- type EChartsMarkPoint
- type EChartsOption
- type EChartsPadding
- type EChartsPosition
- type EChartsSeries
- type EChartsSeriesData
- type EChartsSeriesDataValue
- type EChartsSeriesList
- type EChartsTextStyle
- type EChartsXAxis
- type EChartsXAxisData
- type EChartsYAxis
- type EChartsYAxisData
- type LabelFormatter
- type LegendOption
- type LineStyle
- type Option
- type OptionFunc
- func BackgroundColorOptionFunc(color drawing.Color) OptionFunc
- func BoxOptionFunc(box chart.Box) OptionFunc
- func ChildOptionFunc(child ...ChartOption) OptionFunc
- func FontFamilyOptionFunc(fontFamily string) OptionFunc
- func HeightOptionFunc(height int) OptionFunc
- func LegendOptionFunc(legend LegendOption) OptionFunc
- func PNGTypeOption() OptionFunc
- func PaddingOptionFunc(padding chart.Box) OptionFunc
- func RadarIndicatorOptionFunc(radarIndicator ...RadarIndicator) OptionFunc
- func ThemeOptionFunc(theme string) OptionFunc
- func TitleOptionFunc(title TitleOption) OptionFunc
- func TypeOptionFunc(t string) OptionFunc
- func WidthOptionFunc(width int) OptionFunc
- func XAxisOptionFunc(xAxisOption XAxisOption) OptionFunc
- func YAxisOptionFunc(yAxisOption ...YAxisOption) OptionFunc
- type PieSeriesOption
- type Point
- type RadarIndicator
- type Range
- type Series
- type SeriesData
- type SeriesLabel
- type SeriesList
- type SeriesMarkData
- type SeriesMarkLine
- type SeriesMarkPoint
- type TableOption
- type Theme
- type TitleOption
- type XAxisOption
- type YAxisOption
Constants ¶
const ( ChartTypeLine = "line" ChartTypeBar = "bar" ChartTypePie = "pie" ChartTypeRadar = "radar" ChartTypeFunnel = "funnel" )
const ( ChartOutputSVG = "svg" ChartOutputPNG = "png" )
const ( PositionLeft = "left" PositionRight = "right" PositionCenter = "center" PositionTop = "top" PositionBottom = "bottom" )
const ( OrientHorizontal = "horizontal" OrientVertical = "vertical" )
const ( SeriesMarkDataTypeMax = "max" SeriesMarkDataTypeMin = "min" SeriesMarkDataTypeAverage = "average" )
const (
LegendIconRect = "rect"
)
const ThemeAnt = "ant"
const ThemeDark = "dark"
const ThemeGrafana = "grafana"
const ThemeLight = "light"
const YAxisWidth = 40
TODO 长度是否可以变化
Variables ¶
var ErrFontNotExists = errors.New("font is not exists")
var ErrTableColumnWidthInvalid = errors.New("table column width is invalid")
Functions ¶
func InstallFont ¶ added in v0.0.3
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 NewLegend ¶ added in v1.0.0
func NewLegend(d *Draw, opt LegendOption) *legend
func RenderEChartsToPNG ¶
func RenderEChartsToSVG ¶
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)
Types ¶
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 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
type DrawOption ¶ added in v1.0.0
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 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 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
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 Option ¶ added in v1.0.0
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 RadarIndicator ¶ added in v1.1.0
type Range ¶
type Range struct { Min float64 Max float64 Size int Boundary bool // contains filtered or unexported fields }
func (*Range) AutoDivide ¶ added in v1.0.0
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
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 Theme ¶ added in v1.0.0
type Theme struct {
// contains filtered or unexported fields
}
func (*Theme) GetAxisSplitLineColor ¶ added in v1.0.0
func (*Theme) GetAxisStrokeColor ¶ added in v1.0.0
func (*Theme) GetBackgroundColor ¶ added in v1.0.0
func (*Theme) GetSeriesColor ¶ added in v1.0.0
func (*Theme) GetTextColor ¶ added in v1.0.0
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