google_jsgraph

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2025 License: BSD-3-Clause Imports: 9 Imported by: 2

Documentation

Overview

package google_jsgraph provides google javascript bar graph and pie graph.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Emit added in v0.12.0

func Emit(graphs map[string]Graph) (template.HTML, error)

Emit emits the javascript chunk that renders the graphs. In graphs, the keys are the ids of the div tags where the graphs go. The keys must match [a-z0-9]+ or else Emit returns an error. The return value of Emit belongs in the head section of the html document.

func MustEmit

func MustEmit(graphs map[string]Graph) template.HTML

MustEmit works like Emit except that when Emit returns an error, MustEmit panics.

Types

type BarGraph

type BarGraph struct {

	// The graph data
	Data GraphData

	// Palette consists of the RGB colors to use in the bar graph.
	// e.g []String{"FF0000", "00FF00", "0000FF"}
	Palette []string
}

BarGraph represents a bar graph.

func (*BarGraph) Packages added in v0.11.0

func (b *BarGraph) Packages() []string

func (*BarGraph) WriteCode added in v0.11.0

func (b *BarGraph) WriteCode(name string, w io.Writer) error

type Graph

type Graph interface {

	// Packages returns the Google javascript packages this graph depends on
	Packages() []string

	// WriteCode writes the code within the drawCharts() function that draws
	// this graph. name is the id of the div tag where this graph will go.
	// When Emit or MustEmit calls this, it provides a w that also implements
	// io.ByteWriter and io.StringWriter.
	WriteCode(name string, w io.Writer) error
}

Graph represents a Google javascript graph

type GraphData

type GraphData interface {

	// The number of X data points
	XLen() int

	// The number of Y data points
	YLen() int

	// The title of the X labels
	XTitle() string

	// Return 0-based label for X axis
	XLabel(x int) string

	// Return 0-based label for Y axis
	YLabel(y int) string

	// Return value at (x, y)
	Value(x, y int) float64
}

GraphData represents a dataset to be graphed.

type PieGraph

type PieGraph struct {

	// The graph data. YLen should be 1.
	Data GraphData

	// Optional: Palette consists of the RGB colors to use in the pie graph.
	// e.g []String{"FF0000", "00FF00", "0000FF"}. If omitted, Google chooses
	// the palette.
	Palette []string
}

PieGraph represents a pie graph.

func (*PieGraph) Packages added in v0.11.0

func (p *PieGraph) Packages() []string

func (*PieGraph) WriteCode added in v0.11.0

func (p *PieGraph) WriteCode(name string, w io.Writer) error

Jump to

Keyboard shortcuts

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