Documentation ¶
Index ¶
- Constants
- Variables
- func BoolPointer(b bool) *bool
- func False() *bool
- func FloatPointer(f float64) *float64
- func FormatValueHumanize(value float64, decimals int, ensureTrailingZeros bool) string
- func FormatValueHumanizeShort(value float64, decimals int, ensureTrailingZeros bool) string
- func GetDefaultFont() *truetype.Font
- func GetFont(fontFamily string) *truetype.Font
- func GetNullValue() float64
- func InstallFont(fontFamily string, data []byte) error
- func InstallTheme(name string, opt ThemeOption)
- func RenderEChartsToPNG(options string) ([]byte, error)
- func RenderEChartsToSVG(options string) ([]byte, error)
- func SetDefaultChartDimensions(width, height int)
- func SetDefaultFont(fontFamily string) error
- func SetDefaultTheme(name string) error
- func True() *bool
- type BarChartOption
- type BarSeriesOption
- type Box
- type ChartOption
- type Color
- type ColorPalette
- 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 FontStyle
- type FunnelChartOption
- type FunnelSeriesOption
- type HorizontalBarChartOption
- type LegendOption
- type LineChartOption
- type LineSeriesOption
- type OffsetInt
- type OffsetStr
- type OptionFunc
- func ChildOptionFunc(child ...ChartOption) OptionFunc
- func DimensionsOptionFunc(width, height int) OptionFunc
- func FontOptionFunc(font *truetype.Font) OptionFunc
- func LegendLabelsOptionFunc(labels []string) OptionFunc
- func LegendOptionFunc(legend LegendOption) OptionFunc
- func MarkLineOptionFunc(seriesIndex int, markLineTypes ...string) OptionFunc
- func MarkPointOptionFunc(seriesIndex int, markPointTypes ...string) OptionFunc
- func PNGOutputOptionFunc() OptionFunc
- func PaddingOptionFunc(padding Box) OptionFunc
- func RadarIndicatorOptionFunc(names []string, values []float64) OptionFunc
- func SVGOutputOptionFunc() OptionFunc
- func SeriesShowLabel(show bool) OptionFunc
- func ThemeNameOptionFunc(theme string) OptionFunc
- func ThemeOptionFunc(theme ColorPalette) OptionFunc
- func TitleOptionFunc(title TitleOption) OptionFunc
- func TitleTextOptionFunc(text string, subtext ...string) OptionFunc
- func XAxisDataOptionFunc(data []string) OptionFunc
- func XAxisOptionFunc(xAxisOption XAxisOption) OptionFunc
- func YAxisDataOptionFunc(data []string) OptionFunc
- func YAxisOptionFunc(yAxisOption ...YAxisOption) OptionFunc
- type Painter
- func BarRender(values [][]float64, opts ...OptionFunc) (*Painter, error)
- func FunnelRender(values []float64, opts ...OptionFunc) (*Painter, error)
- func HorizontalBarRender(values [][]float64, opts ...OptionFunc) (*Painter, error)
- func LineRender(values [][]float64, opts ...OptionFunc) (*Painter, error)
- func NewPainter(opts PainterOptions, opt ...PainterOptionFunc) *Painter
- func PieRender(values []float64, opts ...OptionFunc) (*Painter, error)
- func RadarRender(values [][]float64, opts ...OptionFunc) (*Painter, error)
- func Render(opt ChartOption, opts ...OptionFunc) (*Painter, error)
- func TableOptionRenderDirect(opt TableChartOption) (*Painter, error)
- func TableRenderValues(header []string, data [][]string, spanMaps ...map[int]int) (*Painter, error)
- func (p *Painter) ArrowDown(x, y, width, height int, fillColor, strokeColor Color, strokeWidth float64)
- func (p *Painter) ArrowLeft(x, y, width, height int, fillColor, strokeColor Color, strokeWidth float64)
- func (p *Painter) ArrowRight(x, y, width, height int, fillColor, strokeColor Color, strokeWidth float64)
- func (p *Painter) ArrowUp(x, y, width, height int, fillColor, strokeColor Color, strokeWidth float64)
- func (p *Painter) BarChart(opt BarChartOption) error
- func (p *Painter) Bytes() ([]byte, error)
- func (p *Painter) Child(opt ...PainterOptionFunc) *Painter
- func (p *Painter) Circle(radius float64, x, y int, fillColor, strokeColor Color, strokeWidth float64)
- func (p *Painter) Dots(points []Point, fillColor, strokeColor Color, strokeWidth float64, ...)
- func (p *Painter) FillArea(points []Point, fillColor Color)
- func (p *Painter) FunnelChart(opt FunnelChartOption) error
- func (p *Painter) Height() int
- func (p *Painter) HorizontalBarChart(opt HorizontalBarChartOption) error
- func (p *Painter) LineChart(opt LineChartOption) error
- func (p *Painter) LineStroke(points []Point, strokeColor Color, strokeWidth float64)
- func (p *Painter) MarkLine(x, y, width int, fillColor, strokeColor Color, strokeWidth float64, ...)
- func (p *Painter) MeasureText(text string, textRotation float64, fontStyle FontStyle) Box
- func (p *Painter) PieChart(opt PieChartOption) error
- func (p *Painter) Pin(x, y, width int, fillColor, strokeColor Color, strokeWidth float64)
- func (p *Painter) Polygon(center Point, radius float64, sides int, strokeColor Color, ...)
- func (p *Painter) RadarChart(opt RadarChartOption) error
- func (p *Painter) SetBackground(width, height int, color Color)
- func (p *Painter) SmoothLineStroke(points []Point, tension float64, strokeColor Color, strokeWidth float64)
- func (p *Painter) TableChart(opt TableChartOption) error
- func (p *Painter) Text(body string, x, y int, radians float64, fontStyle FontStyle)
- func (p *Painter) TextFit(body string, x, y, width int, fontStyle FontStyle, textAligns ...string) chartdraw.Box
- func (p *Painter) Width() int
- type PainterOptionFunc
- type PainterOptions
- type PieChartOption
- type PieSeriesOption
- type Point
- type RadarChartOption
- type RadarIndicator
- type RadarSeriesOption
- type Series
- type SeriesLabel
- type SeriesList
- func NewSeriesListBar(values [][]float64, opts ...BarSeriesOption) SeriesList
- func NewSeriesListFunnel(values []float64, opts ...FunnelSeriesOption) SeriesList
- func NewSeriesListHorizontalBar(values [][]float64, opts ...BarSeriesOption) SeriesList
- func NewSeriesListLine(values [][]float64, opts ...LineSeriesOption) SeriesList
- func NewSeriesListPie(values []float64, opts ...PieSeriesOption) SeriesList
- func NewSeriesListRadar(values [][]float64, opts ...RadarSeriesOption) SeriesList
- type SeriesMarkData
- type SeriesMarkLine
- type SeriesMarkPoint
- type TableCell
- type TableChartOption
- type ThemeOption
- type TitleOption
- type ValueFormatter
- type XAxisOption
- type YAxisOption
Constants ¶
const ( ChartTypeLine = "line" ChartTypeBar = "bar" ChartTypePie = "pie" ChartTypeRadar = "radar" ChartTypeFunnel = "funnel" ChartTypeHorizontalBar = "horizontalBar" )
const ( ChartOutputSVG = "svg" ChartOutputPNG = "png" )
const ( PositionLeft = "left" PositionRight = "right" PositionCenter = "center" PositionTop = "top" PositionBottom = "bottom" )
const ( AlignLeft = "left" AlignRight = "right" AlignCenter = "center" )
const ( SeriesMarkDataTypeMax = "max" SeriesMarkDataTypeMin = "min" SeriesMarkDataTypeAverage = "average" )
const IconDot = "dot"
const IconRect = "rect"
const ThemeAnt = "ant"
ThemeAnt is an ant styled theme.
const ThemeDark = "dark"
ThemeDark is a dark alternative to the default theme 'light, with series colors from echarts'.
const ThemeGrafana = "grafana"
ThemeGrafana is a grafana styled theme.
const ThemeLight = "light"
ThemeLight is the default theme used, with series colors from echarts.
const ThemeVividDark = "vivid-dark"
ThemeVividDark is a dark alternative to 'ThemeVividLight', with the same bright initial series colors.
const ThemeVividLight = "vivid-light"
ThemeVividLight is an alternative light theme that has red, yellow, and other bright colors initially in the series. It can be a good option when you want the first few series items to grab the most attention.
Variables ¶
var BoxZero = chartdraw.BoxZero
var OffsetCenter = OffsetStr{Left: PositionCenter}
var OffsetLeft = OffsetStr{Left: PositionLeft}
var OffsetRight = OffsetStr{Left: PositionRight}
Functions ¶
func BoolPointer ¶
BoolPointer returns a pointer to the given bool value, useful for configuration.
func FloatPointer ¶
FloatPointer returns a pointer to the given float64 value, useful for configuration.
func FormatValueHumanize ¶ added in v0.3.1
FormatValueHumanize takes in a value and a specified precision, rounding to the specified precision and returning a human friendly number string including commas.
func FormatValueHumanizeShort ¶ added in v0.3.1
FormatValueHumanizeShort takes in a value and a specified precision, rounding to the specified precision and returning a human friendly number string including commas. If the value is over 1,000 it will be reduced to a shorter version with the appropriate k, M, G, T suffix.
func InstallFont ¶
InstallFont installs the font for charts
func InstallTheme ¶
func InstallTheme(name string, opt ThemeOption)
InstallTheme adds a theme to the catalog which can later be retrieved using GetTheme.
func RenderEChartsToPNG ¶
func RenderEChartsToSVG ¶
func SetDefaultChartDimensions ¶ added in v0.4.0
func SetDefaultChartDimensions(width, height int)
SetDefaultChartDimensions sets default width and height of charts if not otherwise specified in their configuration.
func SetDefaultFont ¶
SetDefaultFont set default font by name.
func SetDefaultTheme ¶
SetDefaultTheme sets default theme by name.
Types ¶
type BarChartOption ¶
type BarChartOption struct { // Theme specifies the colors used for the bar chart. Theme ColorPalette // Padding specifies the padding of bar chart. Padding Box // Font is the font used to render the chart. Font *truetype.Font // SeriesList provides the data series. SeriesList SeriesList // XAxis are options for the x-axis. XAxis XAxisOption // YAxis are options for the y-axis (at most two). YAxis []YAxisOption // Title are options for rendering the title. Title TitleOption // Legend are options for the data legend. Legend LegendOption // BarWidth specifies the width of each bar. BarWidth int // RoundedBarCaps set to `true` to produce a bar graph where the bars have rounded tops. RoundedBarCaps *bool // ValueFormatter defines how float values should be rendered to strings, notably for numeric axis labels. ValueFormatter ValueFormatter }
func NewBarChartOptionWithData ¶ added in v0.4.0
func NewBarChartOptionWithData(data [][]float64) BarChartOption
NewBarChartOptionWithData returns an initialized BarChartOption with the SeriesList set for the provided data slice.
type BarSeriesOption ¶ added in v0.4.0
type BarSeriesOption struct { Label SeriesLabel Names []string MarkPoint SeriesMarkPoint MarkLine SeriesMarkLine }
BarSeriesOption provides series customization for NewSeriesListBar or NewSeriesListHorizontalBar.
type ChartOption ¶
type ChartOption struct { // OutputFormat specifies the output type of chart, "svg" or "png", default value is "png". OutputFormat string // Width is the width of chart, default width is 600. Width int // Height is the height of chart, default height is 400. Height int // Theme specifies the colors used for the chart. Built in themes can be loaded using GetTheme with // "light", "dark", "vivid-light", "vivid-dark", "ant" or "grafana". Theme ColorPalette // Padding specifies the padding for chart, default padding is [20, 10, 10, 10]. Padding Box // XAxis are options for the x-axis. XAxis XAxisOption // YAxis are options for the y-axis (at most two). YAxis []YAxisOption // Title are options for rendering the title. Title TitleOption // Legend are options for the data legend. Legend LegendOption // Font is the font to use for rendering the chart. Font *truetype.Font // Box specifies the canvas box for the chart. Box Box // SeriesList provides the data series. SeriesList SeriesList // RadarIndicators are radar indicator list for radar charts. RadarIndicators []RadarIndicator // SymbolShow set this to *false or *true (using False() or True()) to force if the symbols should be shown or hidden. SymbolShow *bool // LineStrokeWidth is the stroke width for line charts. LineStrokeWidth float64 // FillArea set to true to fill the area under the line in line charts FillArea bool // FillOpacity is the opacity (alpha) of the area fill in line charts. FillOpacity uint8 // BarWidth is the width of the bars for bar charts. BarWidth int // BarHeight is the height of the bars for horizontal bar charts. BarHeight int // Children are Child charts to render together. Children []ChartOption // ValueFormatter to format numeric values into labels. ValueFormatter ValueFormatter // contains filtered or unexported fields }
type Color ¶
func ParseColor ¶ added in v0.3.2
ParseColor parses a color from a string. The color can be specified in hex with a `#` prefix (for example '#313233'), in rgb(i,i,i) or rgba(i,i,i,f) format, or as a common name (for example 'red').
type ColorPalette ¶
type ColorPalette interface { IsDark() bool GetAxisStrokeColor() Color GetAxisSplitLineColor() Color GetSeriesColor(int) Color GetBackgroundColor() Color GetTextColor() Color // WithAxisColor will provide a new ColorPalette that uses the specified color for axis values. // This includes the Axis Stroke, Split Line, and Text Color. WithAxisColor(Color) ColorPalette // WithTextColor will provide a new ColorPalette that uses the specified color for text. // This is generally recommended over using the FontColor config values. WithTextColor(Color) ColorPalette // WithSeriesColors will provide a new ColorPalette that uses the specified series colors. WithSeriesColors([]Color) ColorPalette // WithBackgroundColor will provide a new ColorPalette that uses the specified color for the background. WithBackgroundColor(Color) ColorPalette }
func GetDefaultTheme ¶
func GetDefaultTheme() ColorPalette
GetDefaultTheme returns the default theme.
func GetTheme ¶
func GetTheme(name string) ColorPalette
GetTheme returns an installed theme by name, or the default if the theme is not installed.
func MakeTheme ¶
func MakeTheme(opt ThemeOption) ColorPalette
MakeTheme constructs a one-off theme without installing it into the catalog.
type EChartStyle ¶
type EChartStyle struct {
Color string `json:"color"`
}
type EChartsAxisLabel ¶
type EChartsAxisLabel struct {
Formatter string `json:"formatter"`
}
type EChartsLabelOption ¶
type EChartsLegend ¶
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 ¶
type EChartsMarkData struct {
Type string `json:"type"`
}
func (*EChartsMarkData) UnmarshalJSON ¶
func (emd *EChartsMarkData) UnmarshalJSON(data []byte) error
type EChartsMarkLine ¶
type EChartsMarkLine struct {
Data []EChartsMarkData `json:"data"`
}
func (*EChartsMarkLine) ToSeriesMarkLine ¶
func (eml *EChartsMarkLine) ToSeriesMarkLine() SeriesMarkLine
type EChartsMarkPoint ¶
type EChartsMarkPoint struct { SymbolSize int `json:"symbolSize"` Data []EChartsMarkData `json:"data"` }
func (*EChartsMarkPoint) ToSeriesMarkPoint ¶
func (emp *EChartsMarkPoint) ToSeriesMarkPoint() SeriesMarkPoint
type EChartsOption ¶
type EChartsOption struct { Type string `json:"type"` Theme string `json:"theme"` FontFamily string `json:"fontFamily"` Padding EChartsPadding `json:"padding"` Box chartdraw.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 ¶
func (eo *EChartsOption) ToOption() ChartOption
type EChartsPadding ¶
func (*EChartsPadding) UnmarshalJSON ¶
func (eb *EChartsPadding) UnmarshalJSON(data []byte) error
type EChartsPosition ¶
type EChartsPosition string
func (*EChartsPosition) UnmarshalJSON ¶
func (p *EChartsPosition) UnmarshalJSON(data []byte) error
type EChartsSeries ¶
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 configuration Label EChartsLabelOption `json:"label"` MarkPoint EChartsMarkPoint `json:"markPoint"` MarkLine EChartsMarkLine `json:"markLine"` Max *float64 `json:"max"` Min *float64 `json:"min"` }
type EChartsSeriesData ¶
type EChartsSeriesData struct { Value EChartsSeriesDataValue `json:"value"` Name string `json:"name"` ItemStyle EChartStyle `json:"itemStyle"` }
func (*EChartsSeriesData) UnmarshalJSON ¶
func (es *EChartsSeriesData) UnmarshalJSON(data []byte) error
type EChartsSeriesDataValue ¶
type EChartsSeriesDataValue struct {
// contains filtered or unexported fields
}
func (*EChartsSeriesDataValue) First ¶
func (value *EChartsSeriesDataValue) First() float64
func (*EChartsSeriesDataValue) UnmarshalJSON ¶
func (value *EChartsSeriesDataValue) UnmarshalJSON(data []byte) error
type EChartsSeriesList ¶
type EChartsSeriesList []EChartsSeries
func (EChartsSeriesList) ToSeriesList ¶
func (esList EChartsSeriesList) ToSeriesList() SeriesList
type EChartsTextStyle ¶
type EChartsTextStyle struct { Color string `json:"color"` FontFamily string `json:"fontFamily"` FontSize float64 `json:"fontSize"` }
func (*EChartsTextStyle) ToStyle ¶
func (et *EChartsTextStyle) ToStyle() chartdraw.Style
type EChartsXAxis ¶
type EChartsXAxis struct {
Data []EChartsXAxisData
}
func (*EChartsXAxis) UnmarshalJSON ¶
func (ex *EChartsXAxis) UnmarshalJSON(data []byte) error
type EChartsXAxisData ¶
type EChartsYAxis ¶
type EChartsYAxis struct {
Data []EChartsYAxisData `json:"data"`
}
func (*EChartsYAxis) UnmarshalJSON ¶
func (ey *EChartsYAxis) UnmarshalJSON(data []byte) error
type EChartsYAxisData ¶
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"` Data []string `json:"data"` }
type FunnelChartOption ¶
type FunnelChartOption struct { // Theme specifies the colors used for the chart. Theme ColorPalette // Padding specifies the padding of funnel chart. Padding Box // Font is the font used to render the chart. Font *truetype.Font // SeriesList provides the data series. SeriesList SeriesList // Title are options for rendering the title. Title TitleOption // Legend are options for the data legend. Legend LegendOption }
func NewFunnelChartOptionWithData ¶ added in v0.4.0
func NewFunnelChartOptionWithData(data []float64) FunnelChartOption
NewFunnelChartOptionWithData returns an initialized FunnelChartOption with the SeriesList set for the provided data slice.
type FunnelSeriesOption ¶ added in v0.4.0
type FunnelSeriesOption struct { Label SeriesLabel Names []string }
FunnelSeriesOption provides series customization for NewSeriesListFunnel.
type HorizontalBarChartOption ¶
type HorizontalBarChartOption struct { // Theme specifies the colors used for the chart. Theme ColorPalette // Padding specifies the padding of bar chart. Padding Box // Font is the font used to render the chart. Font *truetype.Font // SeriesList provides the data series. SeriesList SeriesList // XAxis are options for the x-axis. XAxis XAxisOption // YAxis are options for the y-axis (at most two). YAxis []YAxisOption // Title are options for rendering the title. Title TitleOption // Legend are options for the data legend. Legend LegendOption // BarHeight specifies the height of each horizontal bar. BarHeight int // ValueFormatter defines how float values should be rendered to strings, notably for numeric axis labels. ValueFormatter ValueFormatter }
func NewHorizontalBarChartOptionWithData ¶ added in v0.4.0
func NewHorizontalBarChartOptionWithData(data [][]float64) HorizontalBarChartOption
NewHorizontalBarChartOptionWithData returns an initialized HorizontalBarChartOption with the SeriesList set for the provided data slice.
type LegendOption ¶
type LegendOption struct { // Show specifies if the legend should be rendered, set this to *false (through False()) to hide the legend. Show *bool // Theme specifies the colors used for the legend. Theme ColorPalette // Data provides text for the legend. Data []string // FontStyle specifies the font, size, and style for rendering the legend. FontStyle FontStyle // Padding specifies space padding around the legend. Padding Box // Offset allows you to specify the position of the legend component relative to the left and top side. Offset OffsetStr // Align is the legend marker and text alignment, it can be 'left', 'right' or 'center', default is 'left'. Align string // Vertical can be set to *true to set the legend orientation to be vertical. Vertical *bool // Icon to show next to the labels. Can be 'rect' or 'dot'. Icon string // OverlayChart can be set to *true to render the legend over the chart. Ignored if Vertical is set to true (always overlapped). OverlayChart *bool }
func (*LegendOption) IsEmpty ¶
func (opt *LegendOption) IsEmpty() bool
IsEmpty checks legend is empty
type LineChartOption ¶
type LineChartOption struct { // Theme specifies the colors used for the line chart. Theme ColorPalette // Padding specifies the padding of line chart. Padding Box // Font is the font used to render the chart. Font *truetype.Font // SeriesList provides the data series. SeriesList SeriesList // XAxis are options for the x-axis. XAxis XAxisOption // YAxis are options for the y-axis (at most two). YAxis []YAxisOption // Title are options for rendering the title. Title TitleOption // Legend are options for the data legend. Legend LegendOption // SymbolShow set this to *false or *true (using False() or True()) to force if the symbols should be shown or hidden. SymbolShow *bool // LineStrokeWidth is the width of the rendered line. LineStrokeWidth float64 // StrokeSmoothingTension should be between 0 and 1. At 0 perfectly straight lines will be used with 1 providing // smoother lines. Because the tension smooths out the line, the line will no longer hit the data points exactly. // The more variable the points, and the higher the tension, the more the line will be moved from the points. StrokeSmoothingTension float64 // FillArea set this to true to fill the area below the line. FillArea bool // FillOpacity is the opacity (alpha) of the area fill. FillOpacity uint8 // ValueFormatter defines how float values should be rendered to strings, notably for numeric axis labels. ValueFormatter ValueFormatter // contains filtered or unexported fields }
func NewLineChartOptionWithData ¶ added in v0.4.0
func NewLineChartOptionWithData(data [][]float64) LineChartOption
NewLineChartOptionWithData returns an initialized LineChartOption with the SeriesList set for the provided data slice.
type LineSeriesOption ¶ added in v0.4.0
type LineSeriesOption struct { Label SeriesLabel Names []string MarkPoint SeriesMarkPoint MarkLine SeriesMarkLine }
LineSeriesOption provides series customization for NewSeriesListLine.
type OffsetInt ¶ added in v0.3.0
type OffsetInt struct { // Left indicates a vertical spacing adjustment from the top. Top int // Left indicates a horizontal spacing adjustment from the left. Left int }
OffsetInt provides an ability to configure a shift from the top or left alignments.
type OffsetStr ¶ added in v0.3.0
type OffsetStr struct { // Left is the distance between the component and the left side of the container. // It can be pixel value (20), percentage value (20%), or position description: 'left', 'right', 'center'. Left string // Top is the distance between the component and the top side of the container. // It can be pixel value (20), or percentage value (20%), or position description: 'top', 'bottom'. Top string }
OffsetStr provides an ability to configure a shift from the top or left alignments using flexible string inputs.
type OptionFunc ¶
type OptionFunc func(opt *ChartOption)
OptionFunc option function
func ChildOptionFunc ¶
func ChildOptionFunc(child ...ChartOption) OptionFunc
ChildOptionFunc adds a Child chart on top of the current one. Use Padding and Box for positioning.
func DimensionsOptionFunc ¶ added in v0.4.0
func DimensionsOptionFunc(width, height int) OptionFunc
DimensionsOptionFunc sets the width and height dimensions of the chart.
func FontOptionFunc ¶
func FontOptionFunc(font *truetype.Font) OptionFunc
FontOptionFunc set font of chart.
func LegendLabelsOptionFunc ¶
func LegendLabelsOptionFunc(labels []string) OptionFunc
LegendLabelsOptionFunc set legend labels of chart
func LegendOptionFunc ¶
func LegendOptionFunc(legend LegendOption) OptionFunc
LegendOptionFunc set legend of chart
func MarkLineOptionFunc ¶
func MarkLineOptionFunc(seriesIndex int, markLineTypes ...string) OptionFunc
MarkLineOptionFunc set mark line for series of chart
func MarkPointOptionFunc ¶
func MarkPointOptionFunc(seriesIndex int, markPointTypes ...string) OptionFunc
MarkPointOptionFunc set mark point for series of chart
func PNGOutputOptionFunc ¶ added in v0.4.0
func PNGOutputOptionFunc() OptionFunc
PNGOutputOptionFunc set png type of chart's output.
func PaddingOptionFunc ¶
func PaddingOptionFunc(padding Box) OptionFunc
PaddingOptionFunc set padding of chart
func RadarIndicatorOptionFunc ¶
func RadarIndicatorOptionFunc(names []string, values []float64) OptionFunc
RadarIndicatorOptionFunc set radar indicator of chart
func SVGOutputOptionFunc ¶ added in v0.4.0
func SVGOutputOptionFunc() OptionFunc
SVGOutputOptionFunc set svg type of chart's output.
func SeriesShowLabel ¶ added in v0.4.0
func SeriesShowLabel(show bool) OptionFunc
SeriesShowLabel set the series show label state for all series.
func ThemeNameOptionFunc ¶
func ThemeNameOptionFunc(theme string) OptionFunc
ThemeNameOptionFunc set them of chart by name.
func ThemeOptionFunc ¶
func ThemeOptionFunc(theme ColorPalette) OptionFunc
ThemeOptionFunc set them of chart
func TitleOptionFunc ¶
func TitleOptionFunc(title TitleOption) OptionFunc
TitleOptionFunc set title of chart
func TitleTextOptionFunc ¶
func TitleTextOptionFunc(text string, subtext ...string) OptionFunc
TitleTextOptionFunc set title text of chart
func XAxisDataOptionFunc ¶
func XAxisDataOptionFunc(data []string) OptionFunc
XAxisDataOptionFunc set x-axis data of chart
func XAxisOptionFunc ¶
func XAxisOptionFunc(xAxisOption XAxisOption) OptionFunc
XAxisOptionFunc set x-axis of chart
func YAxisDataOptionFunc ¶
func YAxisDataOptionFunc(data []string) OptionFunc
YAxisDataOptionFunc set y-axis data of chart
func YAxisOptionFunc ¶
func YAxisOptionFunc(yAxisOption ...YAxisOption) OptionFunc
YAxisOptionFunc set y-axis of chart, supports up to two y-axis.
type Painter ¶
type Painter struct {
// contains filtered or unexported fields
}
Painter is the primary struct for drawing charts/graphs.
func BarRender ¶
func BarRender(values [][]float64, opts ...OptionFunc) (*Painter, error)
BarRender bar chart render
func FunnelRender ¶
func FunnelRender(values []float64, opts ...OptionFunc) (*Painter, error)
FunnelRender funnel chart render
func HorizontalBarRender ¶
func HorizontalBarRender(values [][]float64, opts ...OptionFunc) (*Painter, error)
HorizontalBarRender horizontal bar chart render
func LineRender ¶
func LineRender(values [][]float64, opts ...OptionFunc) (*Painter, error)
LineRender line chart render
func NewPainter ¶
func NewPainter(opts PainterOptions, opt ...PainterOptionFunc) *Painter
NewPainter creates a painter which can be used to render charts to (using for example newLineChart).
func PieRender ¶
func PieRender(values []float64, opts ...OptionFunc) (*Painter, error)
PieRender pie chart render
func RadarRender ¶
func RadarRender(values [][]float64, opts ...OptionFunc) (*Painter, error)
RadarRender radar chart render
func Render ¶
func Render(opt ChartOption, opts ...OptionFunc) (*Painter, error)
func TableOptionRenderDirect ¶ added in v0.4.0
func TableOptionRenderDirect(opt TableChartOption) (*Painter, error)
TableOptionRenderDirect table render with the provided options directly to an image. Table options are different from other charts as they include the state for initializing the Painter, where other charts accept the Painter. If you want to write a Table on an existing Painter use TableOptionRender
func TableRenderValues ¶ added in v0.4.0
TableRenderValues renders a table chart with the simple header and data values provided.
func (*Painter) ArrowDown ¶ added in v0.4.0
func (p *Painter) ArrowDown(x, y, width, height int, fillColor, strokeColor Color, strokeWidth float64)
ArrowDown draws an arrow at the given point and dimensions pointing down.
func (*Painter) ArrowLeft ¶
func (p *Painter) ArrowLeft(x, y, width, height int, fillColor, strokeColor Color, strokeWidth float64)
ArrowLeft draws an arrow at the given point and dimensions pointing left.
func (*Painter) ArrowRight ¶
func (p *Painter) ArrowRight(x, y, width, height int, fillColor, strokeColor Color, strokeWidth float64)
ArrowRight draws an arrow at the given point and dimensions pointing right.
func (*Painter) ArrowUp ¶ added in v0.4.0
func (p *Painter) ArrowUp(x, y, width, height int, fillColor, strokeColor Color, strokeWidth float64)
ArrowUp draws an arrow at the given point and dimensions pointing up.
func (*Painter) BarChart ¶ added in v0.4.0
func (p *Painter) BarChart(opt BarChartOption) error
BarChart renders a bar chart with the provided configuration to the painter.
func (*Painter) Child ¶
func (p *Painter) Child(opt ...PainterOptionFunc) *Painter
Child returns a painter with the passed-in options applied to it. Useful when you want to render relative to only a portion of the canvas via PainterBoxOption.
func (*Painter) Circle ¶
func (p *Painter) Circle(radius float64, x, y int, fillColor, strokeColor Color, strokeWidth float64)
Circle draws a circle at the given coords with a given radius.
func (*Painter) Dots ¶
func (p *Painter) Dots(points []Point, fillColor, strokeColor Color, strokeWidth float64, dotRadius float64)
Dots prints filled circles for the given points.
func (*Painter) FillArea ¶
FillArea draws a filled polygon through the given points, skipping "null" (MaxInt32) break values (filling the area flat between them).
func (*Painter) FunnelChart ¶ added in v0.4.0
func (p *Painter) FunnelChart(opt FunnelChartOption) error
FunnelChart renders a funnel chart with the provided configuration to the painter.
func (*Painter) HorizontalBarChart ¶ added in v0.4.0
func (p *Painter) HorizontalBarChart(opt HorizontalBarChartOption) error
HorizontalBarChart renders a horizontal bar chart with the provided configuration to the painter.
func (*Painter) LineChart ¶ added in v0.4.0
func (p *Painter) LineChart(opt LineChartOption) error
LineChart renders a line chart with the provided configuration to the painter.
func (*Painter) LineStroke ¶
LineStroke draws a line in the graph from point to point with the specified stroke color/width. Points with values of math.MaxInt32 will be skipped, resulting in a gap. Single or isolated points will result in just a dot being drawn at the point.
func (*Painter) MarkLine ¶
func (p *Painter) MarkLine(x, y, width int, fillColor, strokeColor Color, strokeWidth float64, strokeDashArray []float64)
MarkLine draws a horizontal line with a small circle and arrow at the right.
func (*Painter) MeasureText ¶
MeasureText will provide the rendered size of the text for the provided font style.
func (*Painter) PieChart ¶ added in v0.4.0
func (p *Painter) PieChart(opt PieChartOption) error
PieChart renders a pie chart with the provided configuration to the painter.
func (*Painter) Polygon ¶
func (p *Painter) Polygon(center Point, radius float64, sides int, strokeColor Color, strokeWidth float64)
Polygon draws a polygon with the specified center, radius, and number of sides.
func (*Painter) RadarChart ¶ added in v0.4.0
func (p *Painter) RadarChart(opt RadarChartOption) error
RadarChart renders a radar chart with the provided configuration to the painter.
func (*Painter) SetBackground ¶
SetBackground fills the entire painter area with the given color.
func (*Painter) SmoothLineStroke ¶
func (p *Painter) SmoothLineStroke(points []Point, tension float64, strokeColor Color, strokeWidth float64)
SmoothLineStroke draws a smooth curve through the given points using Quadratic Bézier segments and a `tension` parameter in [0..1] with 0 providing straight lines between midpoints and 1 providing a smoother line. Because the tension smooths out the line, the line will no longer hit the provided points exactly. The more variable the points, and the higher the tension, the more the line will be.
func (*Painter) TableChart ¶ added in v0.4.0
func (p *Painter) TableChart(opt TableChartOption) error
TableChart renders a table with the provided configuration to the painter.
func (*Painter) Text ¶
Text draws the given string at the position specified, using the given font style. Specifying radians will rotate the text.
type PainterOptionFunc ¶ added in v0.4.0
type PainterOptionFunc func(*Painter)
PainterOptionFunc defines a function that can modify a Painter after creation.
func PainterBoxOption ¶
func PainterBoxOption(box Box) PainterOptionFunc
PainterBoxOption sets a specific box for the Painter to draw within.
func PainterFontOption ¶
func PainterFontOption(font *truetype.Font) PainterOptionFunc
PainterFontOption sets the default font face for the Painter. This font is used if the FontStyle specified in chart configs does not specify another face.
func PainterPaddingOption ¶
func PainterPaddingOption(padding Box) PainterOptionFunc
PainterPaddingOption sets the padding of the draw painter.
func PainterThemeOption ¶
func PainterThemeOption(theme ColorPalette) PainterOptionFunc
PainterThemeOption sets a color palette theme default for the Painter. This theme is used if the specific chart options don't have a theme set.
type PainterOptions ¶
type PainterOptions struct { // OutputFormat specifies the output type, "svg" or "png", default is "png". OutputFormat string // Width is the width of the draw painter. Width int // Height is the height of the draw painter. Height int // Font is the default font used for rendering text. Font *truetype.Font // Theme is the default theme to be used if the chart does not specify a theme. Theme ColorPalette }
PainterOptions contains parameters for creating a new Painter.
type PieChartOption ¶
type PieChartOption struct { // Theme specifies the colors used for the pie chart. Theme ColorPalette // Padding specifies the padding of pie chart. Padding Box // Font is the font used to render the chart. Font *truetype.Font // SeriesList provides the data series. SeriesList SeriesList // Title are options for rendering the title. Title TitleOption // Legend are options for the data legend. Legend LegendOption // contains filtered or unexported fields }
func NewPieChartOptionWithData ¶ added in v0.4.0
func NewPieChartOptionWithData(data []float64) PieChartOption
NewPieChartOptionWithData returns an initialized PieChartOption with the SeriesList set for the provided data slice.
type PieSeriesOption ¶
type PieSeriesOption struct { Radius string Label SeriesLabel Names []string }
PieSeriesOption provides series customization for NewSeriesListPie.
type RadarChartOption ¶
type RadarChartOption struct { // Theme specifies the colors used for the pie chart. Theme ColorPalette // Padding specifies the padding of pie chart. Padding Box // Font is the font used to render the chart. Font *truetype.Font // SeriesList provides the data series. SeriesList SeriesList // Title are options for rendering the title. Title TitleOption // Legend are options for the data legend. Legend LegendOption // RadarIndicators provides the radar indicator list. RadarIndicators []RadarIndicator // contains filtered or unexported fields }
func NewRadarChartOptionWithData ¶ added in v0.4.0
func NewRadarChartOptionWithData(data [][]float64, names []string, values []float64) RadarChartOption
NewRadarChartOptionWithData returns an initialized RadarChartOption with the SeriesList set for the provided data slice.
type RadarIndicator ¶
type RadarIndicator struct { // Name specifies a name for the iIndicator. Name string // Max is the maximum value of indicator. Max float64 // Min is the minimum value of indicator. Min float64 }
func NewRadarIndicators ¶
func NewRadarIndicators(names []string, values []float64) []RadarIndicator
NewRadarIndicators returns a radar indicator list
type RadarSeriesOption ¶ added in v0.4.0
type RadarSeriesOption struct { Label SeriesLabel Names []string }
RadarSeriesOption provides series customization for NewSeriesListRadar.
type Series ¶
type Series struct { // Type is the type of series, it can be "line", "bar" or "pie". Default value is "line". Type string // Data provides the series data list. Data []float64 // YAxisIndex is the index for the axis, it must be 0 or 1. YAxisIndex int // Label provides the series labels. Label SeriesLabel // Name specifies a name for the series. Name string // Radius for Pie chart, e.g.: 40%, default is "40%" Radius string // MarkPoint provides a series for mark points. MarkPoint SeriesMarkPoint // MarkLine provides a series for mark lines. MarkLine SeriesMarkLine // contains filtered or unexported fields }
Series references a population of data.
type SeriesLabel ¶
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 // FontStyle specifies the font and style for the label. FontStyle FontStyle // Show flag for label, if unset the behavior will be defaulted based on the chart. Show *bool // Distance to the host graphic element. Distance int // TODO - do we want to replace with just Offset? // Position defines the label position. Position string // Offset specifies an offset from the position. Offset OffsetInt }
type SeriesList ¶
type SeriesList []Series
SeriesList is a list of series to be rendered on the chart, typically constructed using NewSeriesListLine, NewSeriesListBar, NewSeriesListHorizontalBar, NewSeriesListPie, NewSeriesListRadar, or NewSeriesListFunnel. These Series can be appended to each other if multiple chart types should be rendered to the same axis.
func NewSeriesListBar ¶ added in v0.4.0
func NewSeriesListBar(values [][]float64, opts ...BarSeriesOption) SeriesList
NewSeriesListBar builds a SeriesList for a bar chart. The first dimension of the values indicates the population of the data, while the second dimension provides the samples for the population (on the X-Axis).
func NewSeriesListFunnel ¶ added in v0.4.0
func NewSeriesListFunnel(values []float64, opts ...FunnelSeriesOption) SeriesList
NewSeriesListFunnel builds a series list for funnel charts.
func NewSeriesListHorizontalBar ¶ added in v0.4.0
func NewSeriesListHorizontalBar(values [][]float64, opts ...BarSeriesOption) SeriesList
NewSeriesListHorizontalBar builds a SeriesList for a horizontal bar chart. Horizontal bar charts are unique in that these Series can not be combined with any other chart type.
func NewSeriesListLine ¶ added in v0.4.0
func NewSeriesListLine(values [][]float64, opts ...LineSeriesOption) SeriesList
NewSeriesListLine builds a SeriesList for a line chart. The first dimension of the values indicates the population of the data, while the second dimension provides the samples for the population.
func NewSeriesListPie ¶ added in v0.4.0
func NewSeriesListPie(values []float64, opts ...PieSeriesOption) SeriesList
NewSeriesListPie builds a SeriesList for a pie chart.
func NewSeriesListRadar ¶ added in v0.4.0
func NewSeriesListRadar(values [][]float64, opts ...RadarSeriesOption) SeriesList
NewSeriesListRadar builds a SeriesList for a Radar chart.
func (SeriesList) Filter ¶
func (sl SeriesList) Filter(chartType string) SeriesList
func (SeriesList) GetMinMax ¶
func (sl SeriesList) GetMinMax(yaxisIndex int) (float64, float64)
GetMinMax get max and min value of series list for a given y-axis index (either 0 or 1).
func (SeriesList) Names ¶
func (sl SeriesList) Names() []string
Names returns the names of series list.
type SeriesMarkData ¶
type SeriesMarkData struct { // Type is the mark data type, it can be "max", "min", "average". "average" is only for mark line. Type string }
type SeriesMarkLine ¶
type SeriesMarkLine struct { // Data is the mark data for the series mark line. Data []SeriesMarkData }
func NewMarkLine ¶
func NewMarkLine(markLineTypes ...string) SeriesMarkLine
NewMarkLine returns a series mark line
type SeriesMarkPoint ¶
type SeriesMarkPoint struct { // SymbolSize is the width of symbol, default value is 30. SymbolSize int // Data is the mark data for the series mark point. Data []SeriesMarkData }
func NewMarkPoint ¶
func NewMarkPoint(markPointTypes ...string) SeriesMarkPoint
NewMarkPoint returns a series mark point
type TableCell ¶
type TableCell struct { // Text the text of table cell Text string // FontStyle contains the configuration for the cell text font. FontStyle FontStyle // FillColor sets a color for this table cell. FillColor drawing.Color // Row the row index of table cell. Row int // Column the column index of table cell. Column int }
type TableChartOption ¶
type TableChartOption struct { // OutputFormat specifies the output type, "svg" or "png". OutputFormat string // Theme specifies the colors used for the table. Theme ColorPalette // Padding specifies the padding of table. Padding Box // Width specifies the width of the table. Width int // Header provides header data for the top of the table. Header []string // Data provides the row and column data for the table. Data [][]string // Spans provide the span for each column on the table. Spans []int // TextAligns specifies the text alignment for each cell on the table. TextAligns []string // FontStyle contains the configuration for the table text font. FontStyle FontStyle // HeaderBackgroundColor provides a background color of header row. HeaderBackgroundColor Color // HeaderFontColor specifies a text color for the header text. HeaderFontColor Color // RowBackgroundColors specifies an array of colors for each row. RowBackgroundColors []Color // BackgroundColor specifies a general background color. BackgroundColor Color // CellModifier is an optional function to modify the style or content of a specific TableCell before they are rendered. CellModifier func(TableCell) TableCell }
type ThemeOption ¶
type TitleOption ¶
type TitleOption struct { // Show specifies if the title should be rendered, set this to *false (through False()) to hide the title. Show *bool // Theme specifies the colors used for the title. Theme ColorPalette // Text specifies the title text, supporting \n for new lines. Text string // Subtext to the title, supporting \n for new lines. Subtext string // Offset allows you to specify the position of the title component relative to the left and top side. Offset OffsetStr // FontStyle specifies the font, size, and style for rendering the title. FontStyle FontStyle // SubtextFontStyle specifies the font, size, and style for rendering the subtext. SubtextFontStyle FontStyle }
type ValueFormatter ¶
ValueFormatter defines a function that can be used to format numeric values.
type XAxisOption ¶
type XAxisOption struct { // Show specifies if the x-axis should be rendered, set this to *false (through False()) to hide the axis. Show *bool // Theme specifies the colors used for the x-axis. Theme ColorPalette // Data provides labels for the x-axis. Data []string // DataStartIndex specifies what index the Data values should start from. DataStartIndex int // Position describes the position of x-axis, it can be 'top' or 'bottom'. Position string // BoundaryGap specifies that the chart should have additional space on the left and right, with data points being // centered between two axis ticks. Default is set based on the dataset density / size to produce an easy-to-read // graph. Specify a *bool (through charts.False() or charts.True()) to enforce a spacing. BoundaryGap *bool // FontStyle specifies the font configuration for each label. FontStyle FontStyle // TextRotation are the radians for rotating the label. TextRotation float64 // LabelOffset is the offset of each label. LabelOffset OffsetInt // ValueFormatter defines how float values should be rendered to strings, notably for numeric axis labels. ValueFormatter ValueFormatter // Unit is a suggestion for how large the axis step is, this is a recommendation only. Larger numbers result in fewer labels. Unit float64 // LabelCount is the number of labels to show on the axis. Specify a smaller number to reduce writing collisions. LabelCount int // LabelCountAdjustment specifies a relative influence on how many labels should be rendered. // Typically, this is negative to result in cleaner graphs, positive values may result in text collisions. LabelCountAdjustment int // contains filtered or unexported fields }
type YAxisOption ¶
type YAxisOption struct { // Show specifies if the y-axis should be rendered, set this to *false (through False()) to hide the axis. Show *bool // Theme specifies the colors used for the x-axis. Theme ColorPalette // Color for y-axis. AxisColor Color // Min, if set this will force the minimum value of y-axis. Min *float64 // Max, if set this will force the maximum value of y-axis. Max *float64 // RangeValuePaddingScale suggest a scale of padding added to the max and min values. RangeValuePaddingScale *float64 // Data provides labels for the y-axis. Data []string // Position describes the position of y-axis, it can be 'left' or 'right'. Position string // FontStyle specifies the font configuration for each label. FontStyle FontStyle // Formatter for replacing y-axis text values. Formatter string // Unit is a suggestion for how large the axis step is, this is a recommendation only. Larger numbers result in fewer labels. Unit float64 // LabelCount is the number of labels to show on the axis. Specify a smaller number to reduce writing collisions. LabelCount int // LabelCountAdjustment specifies a relative influence on how many labels should be rendered. // Typically, this is negative to result in cleaner graphs, positive values may result in text collisions. LabelCountAdjustment int // LabelSkipCount specifies a number of lines between labels where there will be no label and instead just a horizontal line. LabelSkipCount int // SplitLineShow for showing axis split line, set this to true to show the horizontal axis split lines. SplitLineShow *bool // SpineLineShow can be set to enforce if the vertical spine on the axis should be shown or not. // By default, not shown unless a category axis. SpineLineShow *bool // ValueFormatter defines how float values should be rendered to strings, notably for numeric axis labels. ValueFormatter ValueFormatter // contains filtered or unexported fields }
Source Files ¶
- alias.go
- axis.go
- bar_chart.go
- chart_option.go
- charts.go
- color.go
- echarts.go
- font.go
- funnel_chart.go
- horizontal_bar_chart.go
- legend.go
- line_chart.go
- mark_line.go
- mark_point.go
- painter.go
- pie_chart.go
- radar_chart.go
- range.go
- series.go
- series_label.go
- table.go
- theme.go
- title.go
- util.go
- xaxis.go
- yaxis.go