chartjs

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2025 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultBackgroundColors to use on plots.
	DefaultBackgroundColors = []string{
		"rgba(255, 99, 132, 0.2)",
		"rgba(54, 162, 235, 0.2)",
		"rgba(255, 206, 86, 0.2)",
		"rgba(75, 192, 192, 0.2)",
		"rgba(153, 102, 255, 0.2)",
		"rgba(255, 159, 64, 0.2)",
	}
	DefaultBorderColors = []string{
		"rgba(255, 99, 132, 1)",
		"rgba(54, 162, 235, 1)",
		"rgba(255, 206, 86, 1)",
		"rgba(75, 192, 192, 1)",
		"rgba(153, 102, 255, 1)",
		"rgba(255, 159, 64, 1)",
	}
)
View Source
var SrcUrl = "https://cdn.jsdelivr.net/npm/chart.js@3.9.1/dist/chart.js"

SrcUrl is the default URL for the ChartJSUrl.js library. It can be changed to reflect where the notebook will pull it from.

Functions

func MustParse

func MustParse(t *template.Template, text string) *template.Template

func UniqueSuffix

func UniqueSuffix() string

UniqueSuffix returns are unique suffix for JavaScript variable names.

Types

type LineData

type LineData struct {
	Label string

	// BackgroundColor, leave empty and one will be chosen for you.
	BackgroundColor string

	// BorderColor, leave empty and one will be chosen for you.
	BorderColor string

	// IsSecondAxis, if used, set also Has2Axis in LinePlotData.
	IsSecondAxis bool

	Points []XY
}

type LinePlot

type LinePlot struct {
	Id   string
	Data *LinePlotData

	ChartVar            string
	DivId, CanvasId     string
	JavascriptDisplayId string

	// Plot creation content.
	Content string

	// ChartJSUrl is set with SrcUrl.
	ChartJSUrl string

	// DivStyle is inlined in the enclosing `div` html tag.
	DivStyle string

	// CanvasStyle is inlined in the `canvas` html tag that holds the plot.
	CanvasStyle string
}

LinePlot can build and dynamically update line plots.

func NewLinePlot

func NewLinePlot(data *LinePlotData) *LinePlot

func (*LinePlot) AddPoint

func (p *LinePlot) AddPoint(lineIdx int, x, y float64) error

AddPoint executes Javascript code needed to dynamically add one point to the plot. They are only effectively displayed after Update is called.

func (*LinePlot) Plot

func (p *LinePlot) Plot() error

Plot returns the body of the plot in HTML.

func (*LinePlot) Update

func (p *LinePlot) Update() error

Update refreshes the plot after updates with AddPoint (or others).

type LinePlotData

type LinePlotData struct {
	Title, Subtitle string
	HasTwoAxis      bool
	Lines           []*LineData
	XTitle          string
	YTitle, Y2Title string
}

LinePlotData contains potentially multiple lines sharing the same X,Y axis.

func (*LinePlotData) AddPoint

func (l *LinePlotData) AddPoint(lineIdx int, x, y float64)

type XY

type XY struct{ X, Y float64 }

XY represents one point.

Jump to

Keyboard shortcuts

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