plot

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 17 Imported by: 1

Documentation

Overview

`plot` package provides functions for creating and manipulating plots.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateBarChart added in v0.0.9

func CreateBarChart(config BarChartConfig, data ...insyra.IDataList) *charts.Bar

CreateBarChart generates and returns a *charts.Bar object based on BarChartConfig.

func CreateBoxPlot added in v0.0.11

func CreateBoxPlot(config BoxPlotConfig, series ...BoxPlotSeries) *charts.BoxPlot

CreateBoxPlot generates and returns a *charts.BoxPlot object

func CreateFunnelChart added in v0.0.12

func CreateFunnelChart(config FunnelChartConfig, data map[string]float64) *charts.Funnel

CreateFunnelChart generates a funnel chart based on the provided configuration. The data parameter is a map where keys are category names and values are their corresponding values.

func CreateGaugeChart added in v0.0.11

func CreateGaugeChart(config GaugeChartConfig, value float64) *charts.Gauge

CreateGaugeChart generates and returns a *charts.Gauge object

func CreateHeatMap added in v0.2.11

func CreateHeatMap[X heapMapAxisValue, Y heapMapAxisValue](config HeatMapConfig, points ...heatMapPoint[X, Y]) *charts.HeatMap

CreateHeatMap generates and returns a *charts.HeatMap object based on HeatmapConfig. It accepts optional variadic heatMapPoint arguments which will be appended to `config.Data`.

func CreateKlineChart added in v0.0.11

func CreateKlineChart(config KlineChartConfig, klinePoints ...KlinePoint) *charts.Kline

CreateKlineChart generates and returns a *charts.Kline object.

func CreateLineChart added in v0.0.9

func CreateLineChart(config LineChartConfig, data ...insyra.IDataList) *charts.Line

CreateLineChart generates and returns a *charts.Line object based on LineChartConfig.

func CreatePieChart added in v0.0.9

func CreatePieChart(config PieChartConfig, data ...PieItem) *charts.Pie

CreatePieChart generates and returns a *charts.Pie object based on PieChartConfig.

func CreateRadarChart added in v0.0.11

func CreateRadarChart(config RadarChartConfig, series []RadarSeries) *charts.Radar

CreateRadarChart 使用 `RadarChartConfig`(包含 `Indicators` 與 `MaxValues`)及一或多個 `RadarSeries` 生成並返回 *charts.Radar 對象

func CreateSankeyChart added in v0.0.12

func CreateSankeyChart(config SankeyChartConfig, links ...SankeyLink) *charts.Sankey

CreateSankeyChart generates and returns a *charts.Sankey object based on SankeyChartConfig.

func CreateScatterChart added in v0.0.10

func CreateScatterChart(config ScatterChartConfig, data map[string][]ScatterPoint) *charts.Scatter

CreateScatterChart generates and returns a *charts.Scatter object based on ScatterChartConfig.

func CreateThemeRiverChart added in v0.0.12

func CreateThemeRiverChart(config ThemeRiverChartConfig, data ...ThemeRiverData) *charts.ThemeRiver

CreateThemeRiverChart create and return *charts.ThemeRiver object

func CreateWordCloud added in v0.0.11

func CreateWordCloud(config WordCloudConfig, data insyra.IDataList) *charts.WordCloud

CreateWordCloud generates and returns a *charts.WordCloud object based on WordCloudChartConfig.

func HeatMapMissingPoint added in v0.2.11

func HeatMapMissingPoint[X heapMapAxisValue, Y heapMapAxisValue](x X, y Y) heatMapPoint[X, Y]

HeatMapMissingPoint creates a point that is considered missing (renders as "-").

func HeatMapPoint added in v0.2.11

func HeatMapPoint[X heapMapAxisValue, Y heapMapAxisValue](x X, y Y, value float64) heatMapPoint[X, Y]

HeatMapPoint creates a valid point with a numeric value.

func SaveHTML added in v0.0.9

func SaveHTML(chart Renderable, path string, animation ...bool) error

SaveHTML 將圖表渲染並保存為 HTML 文件

func SavePNG added in v0.0.9

func SavePNG(chart Renderable, pngPath string, useOnlineServiceOnFail ...bool) error

SavePNG render chart and save as PNG file using local Chrome or HazelnutParadise online service

Types

type BarChartConfig added in v0.0.9

type BarChartConfig struct {
	Width           string   // Width of the chart (default "900px").
	Height          string   // Height of the chart (default "500px").
	BackgroundColor string   // Background color of the chart (default "white").
	Theme           Theme    // Theme of the chart.
	Title           string   // Title of the chart.
	Subtitle        string   // Subtitle of the chart.
	TitlePos        Position // Optional: Use const PositionXXX.
	HideLegend      bool     // Optional: Whether to hide the legend.
	LegendPos       Position // Optional: Use const PositionXXX.

	XAxis     []string // X-axis data.
	XAxisName string   // Optional: X-axis name.
	YAxisName string   // Optional: Y-axis name.
	// Y axis customization
	YAxisMin         *float64      // Optional: minimum value of Y axis.
	YAxisMax         *float64      // Optional: maximum value of Y axis.
	YAxisSplitNumber *int          // Optional: split number for Y axis.
	YAxisFormatter   string        // Optional: label formatter for Y axis, e.g. "{value}°C".
	Colors           []string      // Optional: Colors for the bars, for example: ["green", "orange"].
	ShowLabels       bool          // Optional: Show labels on the bars.
	LabelPos         LabelPosition // Optional: Use const LabelPositionXXX.
}

BarChartConfig defines the configuration for a bar chart.

type BoxPlotConfig added in v0.0.11

type BoxPlotConfig struct {
	Width           string // Width of the chart (default "900px").
	Height          string // Height of the chart (default "500px").
	BackgroundColor string // Background color of the chart (default "white").
	Theme           Theme  // Theme of the chart.
	Title           string
	Subtitle        string
	TitlePos        Position // Optional: Use const PositionXXX.
	HideLegend      bool     // Whether to hide the legend.
	LegendPos       Position // Optional: Use const PositionXXX.

	XAxis     []string // X-axis data.
	XAxisName string   // Optional: X-axis name.
	YAxisName string   // Optional: Y-axis name.
	// Y axis customization (numeric-only: min/max/split/formatter)
	YAxisMin         *float64 // Optional: minimum value of Y axis.
	YAxisMax         *float64 // Optional: maximum value of Y axis.
	YAxisSplitNumber *int     // Optional: split number for Y axis.
	YAxisFormatter   string   // Optional: label formatter for Y axis, e.g. "{value}°C".
}

BoxPlotConfig defines the configuration for a box plot chart.

type BoxPlotSeries added in v0.2.11

type BoxPlotSeries struct {
	Name  string
	Data  []insyra.IDataList
	Color string // Optional: per-series color
	Fill  bool   // Optional: whether to fill boxes (default false)
}

BoxPlotSeries defines a single series in a box plot.

type FunnelChartConfig added in v0.0.12

type FunnelChartConfig struct {
	Width           string // Width of the chart (default "900px").
	Height          string // Height of the chart (default "500px").
	BackgroundColor string // Background color of the chart (default "white").
	Theme           Theme  // Theme of the chart.
	Title           string
	Subtitle        string
	TitlePos        Position // Optional: Use const PositionXXX.
	HideLegend      bool     // Whether to hide the legend.
	LegendPos       Position // Optional: Use const PositionXXX.

	ShowLabels bool          // whether to show labels
	LabelPos   LabelPosition // Optional: Use const LabelPositionXXX.
}

FunnelChartConfig defines the configuration for a funnel chart.

type GaugeChartConfig added in v0.0.11

type GaugeChartConfig struct {
	Width           string // Width of the chart (default "900px").
	Height          string // Height of the chart (default "500px").
	BackgroundColor string // Background color of the chart (default "white").
	Theme           Theme  // Theme of the chart.
	Title           string
	Subtitle        string
	TitlePos        Position // Optional: Use const PositionXXX.
	HideLegend      bool     // Whether to hide the legend.
	LegendPos       Position // Optional: Use const PositionXXX.

	SeriesName string // series name
}

GaugeChartConfig defines the configuration for a gauge chart.

type HeatMapConfig added in v0.2.11

type HeatMapConfig struct {
	Width           string // Width of the chart (default "900px").
	Height          string // Height of the chart (default "500px").
	BackgroundColor string // Background color of the chart (default "white").
	Theme           Theme  // Theme of the chart.
	Title           string
	Subtitle        string
	TitlePos        Position // Optional: Use const PositionXXX.

	XAxis []string // X-axis data (optional for label-based points).
	YAxis []string // Y-axis data (optional for label-based points).

	// Colors for the visual map (optional)
	Colors []string

	// Min/Max for visual map: if nil, computed from data values
	Min *float64
	Max *float64

	// Calendar mode: if true, `CalendarOpts` will be used and points' X are formatted as dates
	UseCalendar  bool
	CalendarOpts *opts.Calendar
}

HeatMapConfig defines the configuration for a heatmap chart. It supports two modes:

  • grid heatmap: X/Y are either indices (int) or labels (string)
  • calendar heatmap: X should be time.Time and Y is ignored

type KlineChartConfig added in v0.0.11

type KlineChartConfig struct {
	Width           string   // Width of the chart (default "900px").
	Height          string   // Height of the chart (default "500px").
	BackgroundColor string   // Background color of the chart (default "white").
	Theme           Theme    // Theme of the chart.
	Title           string   // Title of the chart.
	Subtitle        string   // Subtitle of the chart.
	TitlePos        Position // Optional: Use const PositionXXX.

	// DateFormat controls how dates are displayed on the X axis. Use Go time format strings or
	// common patterns like "YYYY-MM-DD HH:mm:ss" which will be converted automatically.
	DateFormat string
	DataZoom   bool // Turn on/off data zoom
}

KlineChartConfig defines the configuration for a K-line chart.

type KlinePoint added in v0.2.11

type KlinePoint struct {
	Date  time.Time `json:"date"` // Timestamp of the data point
	Open  float64   `json:"open"`
	High  float64   `json:"high"`
	Low   float64   `json:"low"`
	Close float64   `json:"close"`
}

type LabelPosition added in v0.2.11

type LabelPosition string
const (
	LabelPositionTop               LabelPosition = "top"
	LabelPositionBottom            LabelPosition = "bottom"
	LabelPositionLeft              LabelPosition = "left"
	LabelPositionRight             LabelPosition = "right"
	LabelPositionInside            LabelPosition = "inside"
	LabelPositionInsideLeft        LabelPosition = "insideLeft"
	LabelPositionInsideRight       LabelPosition = "insideRight"
	LabelPositionInsideTop         LabelPosition = "insideTop"
	LabelPositionInsideBottom      LabelPosition = "insideBottom"
	LabelPositionInsideTopLeft     LabelPosition = "insideTopLeft"
	LabelPositionInsideBottomLeft  LabelPosition = "insideBottomLeft"
	LabelPositionInsideTopRight    LabelPosition = "insideTopRight"
	LabelPositionInsideBottomRight LabelPosition = "insideBottomRight"
)

type LineChartConfig added in v0.0.9

type LineChartConfig struct {
	Width           string   // Width of the chart (default "900px").
	Height          string   // Height of the chart (default "500px").
	BackgroundColor string   // Background color of the chart (default "white").
	Theme           Theme    // Theme of the chart.
	Title           string   // Title of the chart.
	Subtitle        string   // Subtitle of the chart.
	TitlePos        Position // Optional: Use const PositionXXX.
	HideLegend      bool     // Optional: Whether to hide the legend.
	LegendPos       Position // Optional: Use const PositionXXX.

	XAxis     []string // X-axis data.
	XAxisName string   // Optional: X-axis name.

	// Y axis customization
	YAxisName        string   // Optional: Y-axis name.
	YAxis            []string // Optional: Y-axis category labels (if provided treated as category).
	YAxisMin         *float64 // Optional: minimum value of Y axis.
	YAxisMax         *float64 // Optional: maximum value of Y axis.
	YAxisSplitNumber *int     // Optional: split number for Y axis.
	YAxisFormatter   string   // Optional: label formatter for Y axis, e.g. "{value}°C".

	Colors     []string // Optional: Colors for the lines, for example: ["blue", "red"].
	ShowLabels bool     // Optional: Show labels on the lines.
	LabelPos   string   // Optional: "top" | "bottom" | "left" | "right", default: "top".
	Smooth     bool     // Optional: Make the lines smooth.
	FillArea   bool     // Optional: Fill the area under the lines.
}

LineChartConfig defines the configuration for a line chart.

type PieChartConfig added in v0.0.9

type PieChartConfig struct {
	Width           string   // Width of the chart (default "900px").
	Height          string   // Height of the chart (default "500px").
	BackgroundColor string   // Background color of the chart (default "white").
	Theme           Theme    // Theme of the chart.
	Title           string   // Title of the chart.
	Subtitle        string   // Subtitle of the chart.
	TitlePos        Position // Optional: Use const PositionXXX.
	HideLegend      bool     // Optional: Whether to hide the legend.
	LegendPos       Position // Optional: Use const PositionXXX.

	Colors      []string // Optional: Colors for the slices, for example: ["green", "orange"].
	ShowLabels  bool     // Optional: Show labels on the slices.
	ShowPercent bool     // Optional: Show percentage on labels.
	LabelPos    LabelPosition
	RoseType    string   // Optional: "radius" or "area" for rose charts.
	Radius      []string // Optional: Radius configuration. First value is inner radius, second is outer radius, for example: ["40%", "75%"].
	Center      []string // Optional: Center position, for example: ["50%", "50%"].
}

PieChartConfig defines the configuration for a pie chart.

type PieItem added in v0.2.11

type PieItem struct {
	Name  string  // Label/name of the pie slice.
	Value float64 // Value of the pie slice.
}

PieItem represents a single item in a pie chart.

type Position added in v0.2.11

type Position string
const (
	PositionTop    Position = "top"
	PositionBottom Position = "bottom"
	PositionLeft   Position = "left"
	PositionRight  Position = "right"
)

type RadarChartConfig added in v0.0.11

type RadarChartConfig struct {
	Width           string   // Width of the chart (default "900px").
	Height          string   // Height of the chart (default "500px").
	BackgroundColor string   // Background color of the chart (default "white").
	Theme           Theme    // Theme of the chart.
	Title           string   // Title of the chart.
	Subtitle        string   // Subtitle of the chart.
	TitlePos        Position // Optional: Use const PositionXXX.
	HideLegend      bool     // Optional: Whether to hide the legend.
	LegendPos       Position // Optional: Use const PositionXXX.

	Indicators []string           // Optional: Automatically generated if not provided.
	MaxValues  map[string]float32 // Optional: Automatically generated if not provided.
}

RadarChartConfig 定義雷達圖的配置

type RadarSeries added in v0.2.11

type RadarSeries struct {
	Name   string
	Values []float32 // 與 RadarDataset.Indicators 順序對齊
	Color  string    // optional
}

RadarSeries 是單一系列資料

type Renderable added in v0.0.9

type Renderable interface {
	Render(w io.Writer) error
	RenderContent() []byte
}

Renderer Any kinds of charts have their render implementation, and you can define your own render logic easily.

type SankeyChartConfig added in v0.0.12

type SankeyChartConfig struct {
	Width           string   // Width of the chart (default "900px").
	Height          string   // Height of the chart (default "500px").
	BackgroundColor string   // Background color of the chart (default "white").
	Theme           Theme    // Theme of the chart.
	Title           string   // Title of the chart.
	Subtitle        string   // Subtitle of the chart.
	TitlePos        Position // Optional: Use const PositionXXX.

	Nodes      []string // Sankey chart node data (string slice)
	Curveness  float32  // Line curvature
	Color      string   // Line color, e.g., "source", "target", or a specific color code
	ShowLabels bool     // Whether to display labels
}

SankeyChartConfig defines the configuration for a Sankey chart.

type SankeyLink struct {
	Source string  `json:"source"`
	Target string  `json:"target"`
	Value  float32 `json:"value"`
}

SankeyLink custom link structure.

type ScatterChartConfig added in v0.0.10

type ScatterChartConfig struct {
	Width           string   // Width of the chart (default "900px").
	Height          string   // Height of the chart (default "500px").
	BackgroundColor string   // Background color of the chart (default "white").
	Theme           Theme    // Theme of the chart.
	Title           string   // Title of the chart.
	Subtitle        string   // Subtitle of the chart.
	TitlePos        Position // Optional: Use const PositionXXX.
	HideLegend      bool     // Optional: Whether to hide the legend.
	LegendPos       Position // Optional: Use const PositionXXX.

	XAxisName        string   // Optional: X-axis name.
	XAxisMin         *float64 // Optional: minimum value of X axis.
	XAxisMax         *float64 // Optional: maximum value of X axis.
	XAxisSplitNumber *int     // Optional: split number for X axis.
	XAxisFormatter   string   // Optional: label formatter for X axis, e.g. "{value}°C".

	YAxisName        string        // Optional: Y-axis name.
	YAxisMin         *float64      // Optional: minimum value of Y axis.
	YAxisMax         *float64      // Optional: maximum value of Y axis.
	YAxisSplitNumber *int          // Optional: split number for Y axis.
	YAxisFormatter   string        // Optional: label formatter for Y axis, e.g. "{value}°C".
	Colors           []string      // Optional: Colors for the scatter points.
	ShowLabels       bool          // Optional: Show labels on the scatter points.
	LabelPos         LabelPosition // Optional: Position of the labels, default is "right".
	SplitLine        bool          // Optional: Whether to show split lines on the X and Y axes.
	Symbol           []string      // Optional: Symbol of the scatter points. Default is "circle". If there are multiple series, you can specify different symbols for each series. If the length of the array is less than the number of series, the remaining series will repeat the order of the symbols.
	SymbolSize       int           // Optional: Size of the scatter points. Default is 10.
}

ScatterChartConfig defines the configuration for a scatter chart.

type ScatterPoint added in v0.2.11

type ScatterPoint struct {
	X float64
	Y float64
}

ScatterPoint represents a 2D point for scatter charts.

type Theme added in v0.2.11

type Theme string
const (
	ThemeChalk         Theme = types.ThemeChalk
	ThemeEssos         Theme = types.ThemeEssos
	ThemeInfographic   Theme = types.ThemeInfographic
	ThemeMacarons      Theme = types.ThemeMacarons
	ThemePurplePassion Theme = types.ThemePurplePassion
	ThemeRoma          Theme = types.ThemeRoma
	ThemeRomantic      Theme = types.ThemeRomantic
	ThemeShine         Theme = types.ThemeShine
	ThemeVintage       Theme = types.ThemeVintage
	ThemeWalden        Theme = types.ThemeWalden
	ThemeWesteros      Theme = types.ThemeWesteros
	ThemeWonderland    Theme = types.ThemeWonderland
)

type ThemeRiverAxisType added in v0.2.11

type ThemeRiverAxisType string
const (
	ThemeRiverAxisTypeTime ThemeRiverAxisType = "time"
)

Other axis types (value, category, log) seem not inplemented in go-echarts ThemeRiver yet.

type ThemeRiverChartConfig added in v0.0.12

type ThemeRiverChartConfig struct {
	Width           string   // Width of the chart (default "900px").
	Height          string   // Height of the chart (default "500px").
	BackgroundColor string   // Background color of the chart (default "white").
	Theme           Theme    // Theme of the chart.
	Title           string   // Title of the chart.
	Subtitle        string   // Subtitle of the chart.
	TitlePos        Position // Optional: Use const PositionXXX.
	HideLegend      bool     // Optional: Whether to hide the legend.
	LegendPos       Position // Optional: Use const PositionXXX.

	// Axis configuration: supports "value", "category", "time", "log".
	// If empty, defaults to "time" (preserves previous behavior).
	AxisType ThemeRiverAxisType // Use ThemeRiverAxisTypeXXX
	AxisData []string           // Optional: categories for category axis (xAxis.data)
	AxisMin  *float64           // Optional: min value for value/log axes
	AxisMax  *float64           // Optional: max value for value/log axes
}

ThemeRiverChartConfig define chart config and X axis options.

type ThemeRiverData added in v0.0.12

type ThemeRiverData struct {
	Date  string  // date, format: "yyyy/MM/dd"
	Value float64 // value
	Name  string  // name/series name
}

ThemeRiverData define single data struct.

type WordCloudConfig added in v0.0.11

type WordCloudConfig struct {
	Width           string   // Width of the chart (default "900px").
	Height          string   // Height of the chart (default "500px").
	BackgroundColor string   // Background color of the chart (default "white").
	Theme           Theme    // Theme of the chart.
	Title           string   // Title of the chart.
	Subtitle        string   // Subtitle of the chart.
	TitlePos        Position // Optional: Use const PositionXXX.

	Shape     WordCloudShape // Optional: Shape of the word cloud. Use const WordCloudShapeXXX.
	SizeRange []float32      // Optional: Size range for the words, e.g., [14, 80].
}

WordCloudConfig defines the configuration for a word cloud chart.

type WordCloudShape added in v0.2.11

type WordCloudShape string
const (
	WordCloudShapeCircle    WordCloudShape = "circle"
	WordCloudShapeRect      WordCloudShape = "rect"
	WordCloudShapeRoundRect WordCloudShape = "roundRect"
	WordCloudShapeTriangle  WordCloudShape = "triangle"
	WordCloudShapeDiamond   WordCloudShape = "diamond"
	WordCloudShapePin       WordCloudShape = "pin"
	WordCloudShapeArrow     WordCloudShape = "arrow"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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