Documentation
¶
Overview ¶
Package plot renders interactive line, stacked-bar and pie charts (backed by uPlot) as an HTML fragment, so any Go web app can embed a chart by calling Render with tabular data.
Mount Handler under a path prefix and include HeadTags(prefix) in the page's <head>; then Render returns a container element plus the inline script that draws into it once those assets have loaded:
mux.Handle("/plot/", http.StripPrefix("/plot/", plot.Handler()))
head := plot.HeadTags("/plot/")
chart, err := plot.Render("chart-1", plot.Data{Columns: cols, Values: rows}, plot.Options{Caption: "Requests"})
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
Handler serves the package's static assets (uPlot library and the chart rendering script).
Types ¶
type Data ¶
Data is a generic tabular dataset to chart.
In the default column shape, the first column is the X axis and each remaining column is one series. In row shape (Options.Rows), each row is (x, y, label) and rows sharing a label form one series. For Options.Kind Pie, each row is (count, label) or (label, count).
type Options ¶
type Options struct {
Kind Kind `json:"kind,omitempty"` // Default Line.
// Rows treats Data as (x, y, label) rows instead of (x, y1, y2, ...) columns. Ignored for Pie.
Rows bool `json:"rows,omitempty"`
// StackedBars renders a stacked bar chart instead of lines. Ignored for Pie.
StackedBars bool `json:"stackedBars,omitempty"`
// Time treats the X axis as UTC Unix timestamps. Ignored for Pie.
Time bool `json:"time,omitempty"`
// TimeAxisFmt overrides the X axis label format, e.g. "{YYYY}-{MM}". Only applies with Time.
TimeAxisFmt string `json:"timeAxisFmt,omitempty"`
Caption string `json:"caption,omitempty"`
Height int `json:"height,omitempty"` // Pixels, default 300.
// PieTotal overrides the computed total, for a Pie chart showing a partial breakdown.
PieTotal float64 `json:"pieTotal,omitempty"`
}
Options configures how Data is rendered.