gosplat

package module
Version: v0.0.0-...-adf3e54 Latest Latest
Warning

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

Go to latest
Published: May 8, 2014 License: MIT Imports: 8 Imported by: 0

README

gosplat

Easily generate HTML/Javascript graphs in go with dygraphs/googlecharts etc...

gosplat generates an HTML file with Javascript embedded in the page to plot the data.

More documentation about google charts: https://developers.google.com/chart/

Installation:

go get github.com/agonopol/gosplat

Import:

import "github.com/agonopol/gosplat"

Example:

func Linechart() {
	//Create a frame to put charts in
	f := gosplat.NewFrame("Linechart Example Frame")
	
	//Create a chart
	v := gosplat.NewChart()
	
	//Add some random data
	v.Append(map[string]interface{}{"date": "2011/07/23", "thing": 10, "thong": 20, "whatevs": 14})
	v.Append(map[string]interface{}{"date": "2011/07/24", "thing": 12, "thong": 24, "whatevs": 24})
	v.Append(map[string]interface{}{"date": "2011/07/24", "thing": 12, "thong": 7, "whatevs": 11})
	
	//Add the chart to the Frame
	f.Append("Linechart Example", v.Linechart())
	
	//Preview generates a tmp html file and opens it with the default browser
	err := f.Preview()
	if err != nil {
		panic(err)
	}
	
	//Html returns bytes.Buffer of the html
	buffer, err := f.Html()
	if err != nil {
		panic(err)
	}
	println(buffer.String())
}

Supported Charts:

  • barchart
  • candlestick
  • columnchart
  • combochart
  • linechart
  • piechart
  • scatter
  • table
  • timeseries

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HTML = `` /* 10145-byte string literal not displayed */

Functions

This section is empty.

Types

type Chart

type Chart struct {
	// contains filtered or unexported fields
}

Chart represents one chart in the frame

func NewChart

func NewChart() *Chart

NewChart greates and initializes an empty Chart

func (*Chart) Append

func (v *Chart) Append(item interface{})

Append accumulates datapoints for the chart Depending on the type of chart you're planning to make Append takes iether a map[string]interface{} or []interface{}

func (*Chart) Barchart

func (v *Chart) Barchart(options ...map[string]interface{}) map[string]interface{}

func (*Chart) Candlestick

func (v *Chart) Candlestick(options ...map[string]interface{}) map[string]interface{}

func (*Chart) Columnchart

func (v *Chart) Columnchart(options ...map[string]interface{}) map[string]interface{}

func (*Chart) Combochart

func (v *Chart) Combochart(options ...map[string]interface{}) map[string]interface{}

func (*Chart) Linechart

func (v *Chart) Linechart(options ...map[string]interface{}) map[string]interface{}

func (*Chart) Piechart

func (v *Chart) Piechart(options ...map[string]interface{}) map[string]interface{}

func (*Chart) Scatter

func (v *Chart) Scatter(options ...map[string]interface{}) map[string]interface{}

func (*Chart) Table

func (v *Chart) Table(options ...map[string]interface{}) map[string]interface{}

func (*Chart) Timeseries

func (v *Chart) Timeseries(options ...map[string]interface{}) map[string]interface{}

func (*Chart) Treemap

func (v *Chart) Treemap(options ...map[string]interface{}) map[string]interface{}

type Frame

type Frame struct {
	// contains filtered or unexported fields
}

Frame holds a series of rows/charts in one page

func NewFrame

func NewFrame(title string) *Frame

NewFrame Creates a new titled frame

func (*Frame) Append

func (f *Frame) Append(title string, v map[string]interface{}, height ...string)

Append adds a chart with height of the chart as an optinal argument

func (*Frame) AppendRow

func (f *Frame) AppendRow(row *Row)

AppendRow adds a Row in sequence

func (*Frame) Html

func (f *Frame) Html() (*bytes.Buffer, error)

Html generates the page

func (*Frame) Preview

func (f *Frame) Preview() error

Preview generates the page and opens it with the default browser

type Row

type Row struct {
	Title          string `json:"title"`
	Visualizations []*view
}

Row allows to put two or three charts in one div, horizontally aligned as a grid

func NewRow

func NewRow(title string) *Row

NewRow you Creates a new empty Row

func (*Row) Append

func (r *Row) Append(title string, viz map[string]interface{}, height ...string) error

Append adds a graphed chart to a Row Currently only up to 3 rows are recommended, as more won't fit on a page

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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