charts

package module
v0.0.0-...-816fd83 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2017 License: MIT Imports: 2 Imported by: 4

README

GopherJS bindings for frappe/charts

Go Report Card GoDoc

"Simple, responsive, modern SVG Charts with zero dependencies"

This library provides a type-safe, builder-based API for the simple and awesome frappe/charts.

Event listener with navigable bar chart:

Alt text

Various chart operations (append, remove, pop) with (mock "realtime") randomized data and actions:

Alt text

Contents

Installation

Built on go 1.9

go get -u github.com/cnguy/gopherjs-frappe-charts

Make sure you also have the necessary JS files.

Currently, this API supports frappe/charts@0.0.7 (maybe 0.0.8 too, since it seems that they didn't change the API in that version).

Dependencies will be managed via dep in the future.

Unfortunately, gopherjs is not vendorable at the moment.

Breaking Changes

This libary seeks to be updated to always work with the latest version of frappe charts. It also seeks to have a clean API so that users can easily bring in charts into their GopherJS-based website. One can also expect that this library will improve as I improve at Go.

Frappe hasn't changed their API dramatically so far, so one can expect that this library won't change dramatically as well. If there are breaking changes, it should be easy to update one's code by simply following the type errors.

The Bare Minimum

Following examples assume an HTML file like so:

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>GopherJS bindings for frappe-charts</title>
</head>
<body>
	<div id="chart"></div>
	<div id="chart-2"></div>
	<div id="heatmap"></div>
	<script src="https://unpkg.com/frappe-charts@0.0.7/dist/frappe-charts.min.iife.js"></script>
	<script src="static.js" data-cover></script>
</body>
</html>

where static.js is the name of your bundled JS file when your folder is named static and you run gopherjs build.

package main

import (
	charts "github.com/cnguy/gopherjs-frappe-charts"
)

func main() {
	chartData := charts.NewChartData()
	chartData.Labels = []string{
		"1", "2", "3",
	}
	chartData.Datasets = []*charts.Dataset{
		charts.NewDataset(
			"Some Data",
			[]float64{25, 40, 30},
		),
		charts.NewDataset(
			"Another Set",
			[]float64{25, 50, -10},
		),
	}

	_ = charts.NewBarChart("#chart", chartData).Render()
}

Alt text

This is the bare minimum needed to create a chart. Try swapping NewBarChart with other functions such as NewPercentageChart or NewPieChart.

frappe already sets defaults for a lot of properties. All New${Type}Chart calls handles the two necessary properties (the title and the chart data).

Everything else is optional (the title, colors, etc).

To learn how to provide more arguments, scroll down to Usage.

Usage

Simply declare chart data via NewChartData() and pass in array of *Datasets constructed by NewDataset().

This data can then be passed in to 99% of the charts (Heatmap is different).

This library uses the builder pattern to handle optional configurations. Every chart can be immediately rendered simply by doing

NewSomeChart("#parent", myData).Render()

If you would like to use optional configuration, check out the docs or simply just use your IDE (NewSomeChart returns a chainable object).

Tip: Prefer using the helpers instead of struct literals.

Hello World:
package main

import (
	charts "github.com/cnguy/gopherjs-frappe-charts"
)

func main() {
	// Prepare data
	chartData := charts.NewChartData()
	chartData.Labels = []string{
		"12am-3am", "3am-6pm", "6am-9am", "9am-12am",
		"12pm-3pm", "3pm-6pm", "6pm-9pm", "9am-12am",
	}
	chartData.Datasets = []*charts.Dataset{
		charts.NewDataset(
			"Some Data",
			[]float64{25, 40, 30, 35, 8, 52, 17, -4},
		),
		charts.NewDataset(
			"Another Set",
			[]float64{25, 50, -10, 15, 18, 32, 27, 14},
		),
	}

	chart := charts.NewBarChart("#chart", chartData).
		WithHeight(250). // `150` is default if this call is not applied.
		WithColors([]string{"light-blue", "violet"}).
		Render() // not calling Render returns a XXXChartArgs instance instead

	// TIP: Try swapping NewBarChart with NewPercentageChart or NewScatterChart
	// to see how easy it is to swap to a different type of chart.
	println(chart) // to suppress the annoying error
}

Output 1:

Alt text

Navigable:
package main

import (
	charts "github.com/cnguy/gopherjs-frappe-charts"
)

func main() {
	// Prepare data
	chartData := charts.NewChartData()
	chartData.Labels = []string{
		"2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017",
	}
	values := []float64{17, 40, 33, 44, 126, 156, 324, 333, 478, 495, 373}
	dataset := charts.NewDataset("Events", values)
	chartData.Datasets = []*charts.Dataset{dataset}

	chartTitle := "Fireball/Bolide Events - Yearly (more than 5 reports)"
	chart := charts.NewBarChart("#chart", chartData).
		WithTitle(chartTitle).
		WithColors([]string{"orange"}).
		SetIsNavigable(true). // ChartArgs#IsNavigable = 1
		SetIsSeries(true).    // ChartArgs#IsSeries = 1
		Render()

	println(chart)
}

Output 2:

Using left/right arrow keys to traverse the graph

Alt text

Line Properties:
package main

import (
	charts "github.com/cnguy/gopherjs-frappe-charts"
	chartsUtils "github.com/cnguy/gopherjs-frappe-charts/utils"
)

func main() {
	// Prepare data
	chartData := charts.NewChartData()
	chartData.Labels = chartsUtils.NumberLabelsToStr([]int{
		1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976,
		1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986,
		1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
		1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
		2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016,
	})
	values := []float64{
		132.9, 150.0, 149.4, 148.0, 94.4, 97.6, 54.1, 49.2, 22.5, 18.4,
		39.3, 131.0, 220.1, 218.9, 198.9, 162.4, 91.0, 60.5, 20.6, 14.8,
		33.9, 123.0, 211.1, 191.8, 203.3, 133.0, 76.1, 44.9, 25.1, 11.6,
		28.9, 88.3, 136.3, 173.9, 170.4, 163.6, 99.3, 65.3, 45.8, 24.7,
		12.6, 4.2, 4.8, 24.9, 80.8, 84.5, 94.0, 113.3, 69.8, 39.8,
	}
	dataset := charts.NewDataset("", values)
	chartData.Datasets = []*charts.Dataset{dataset}

	chartTitle := "Mean Total Sunspot Count - Yearly"
	chart := charts.NewLineChart("#chart", chartData).
		WithTitle(chartTitle).
		WithColors([]string{"blue"}).
		SetShowDots(false).
		SetHeatline(true).
		SetRegionFill(true).
		SetXAxisMode("tick").
		SetYAxisMode("span").
		SetIsSeries(true).
		Render()

	println(chart)
}

Output 3:

Alt text

Simple Aggregations:
package main

import (
	"time"

	charts "github.com/cnguy/gopherjs-frappe-charts"
)

func main() {
	chartData := charts.NewChartData()
	chartData.Labels = []string{
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
	}
	chartData.Datasets = []*charts.Dataset{
		charts.NewDataset("", []float64{25, 40, 30, 35, 8, 52, 17}),
		charts.NewDataset("", []float64{25, 50, -10, 15, 18, 32, 27}),
	}

	chart := charts.NewBarChart("#chart", chartData).
		WithColors([]string{"purple", "orange"}).
		Render()

	time.Sleep(1 * time.Second)
	chart.ShowSums()

	time.Sleep(1 * time.Second)
	chart.HideSums()

	time.Sleep(1 * time.Second)
	chart.ShowAverages()

	time.Sleep(1 * time.Second)
	chart.HideAverages()
}

Output 4:

Alt text

Event Listener:
package main

import (
	charts "github.com/cnguy/gopherjs-frappe-charts"
)

func main() {
	// Make bar chart
	reportCountList := []float64{17, 40, 33, 44, 126, 156,
		324, 333, 478, 495, 373}
	barChartData := charts.NewChartData()
	barChartData.Labels = []string{
		"2007", "2008", "2009", "2010", "2011", "2012",
		"2013", "2014", "2015", "2016", "2017",
	}
	barChartData.Datasets = []*charts.Dataset{
		charts.NewDataset("Events", reportCountList),
	}
	barChartTitle := "Fireball/Bolide Events - Yearly (more than 5 reports"
	barChart := charts.NewBarChart("#chart", barChartData).
		WithTitle(barChartTitle).
		WithHeight(180).
		WithColors([]string{"orange"}).
		SetIsNavigable(true).
		SetIsSeries(true).
		Render()

	// Make line chart
	lineChartValues := []float64{36, 46, 45, 32, 27, 31, 30, 36, 39, 49, 0, 0}
	lineChartData := charts.NewChartData()
	lineChartData.Labels = []string{
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
	}
	lineChartData.Datasets = []*charts.Dataset{
		charts.NewDataset("", lineChartValues),
	}
	lineChart := charts.NewLineChart("#chart-2", lineChartData).
		WithHeight(180).
		WithColors([]string{"green"}).
		SetIsSeries(true).
		Render()

	// Prepare update values for event listener
	moreLineData := []*charts.UpdateValueSet{
		charts.NewUpdateValueSet([]float64{4, 0, 3, 1, 1, 2, 1, 2, 1, 0, 1, 1}),
		charts.NewUpdateValueSet([]float64{2, 3, 3, 2, 1, 4, 0, 1, 2, 7, 11, 4}),
		charts.NewUpdateValueSet([]float64{7, 7, 2, 4, 0, 1, 5, 3, 1, 2, 0, 1}),
		charts.NewUpdateValueSet([]float64{0, 2, 6, 2, 2, 1, 2, 3, 6, 3, 7, 10}),
		charts.NewUpdateValueSet([]float64{9, 10, 8, 10, 6, 5, 8, 8, 24, 15, 10, 13}),
		charts.NewUpdateValueSet([]float64{9, 13, 16, 9, 4, 5, 7, 10, 14, 22, 23, 24}),
		charts.NewUpdateValueSet([]float64{20, 22, 28, 19, 28, 19, 14, 19, 51, 37, 29, 38}),
		charts.NewUpdateValueSet([]float64{29, 20, 22, 16, 16, 19, 24, 26, 57, 31, 46, 2}),
		charts.NewUpdateValueSet([]float64{36, 24, 38, 27, 15, 22, 24, 38, 32, 57, 139, 26}),
		charts.NewUpdateValueSet([]float64{37, 36, 32, 33, 12, 34, 52, 45, 58, 57, 64, 35}),
		charts.NewUpdateValueSet([]float64{36, 46, 45, 32, 27, 31, 30, 36, 39, 49, 0, 0}),
	}

	barChart.AddDataSelectListener(func(event *charts.DataSelectEvent) {
		updateValues := &charts.UpdateValuesArgs{
			Values: []*charts.UpdateValueSet{moreLineData[event.Index]},
			// keep labels same as before
			Labels: lineChartData.Labels,
		}
		lineChart.UpdateValues(updateValues)
	})
}

Output 5:

Alt text

Heatmaps
package main

import (
	"math/rand"
	"strconv"

	charts "github.com/cnguy/gopherjs-frappe-charts"
)

func main() {
	data := make(map[string]int)
	currentTimestamp := 1477699200
	for i := 0; i < 375; i++ {
		data[strconv.Itoa(currentTimestamp)] = rand.Intn(10)
		currentTimestamp += 86400
	}
	charts.NewHeatmapChart("#chart", data).
		WithHeight(115).
		/* Halloween colors */
		// WithLegendColors([]string{"#ebedf0", "#fdf436", "#ffc700", "#ff9100", "#06001c"}).
		Render()
}
With discrete domains set to default

Alt text

With discrete domains set to 1 via chartArgs.SetDiscreteDomain(true)

Alt text

With different colors

Alt text

Realtime
package main

import (
	"math/rand"
	"strconv"
	"time"

	charts "github.com/cnguy/gopherjs-frappe-charts"
)

func main() {
	chartData := charts.NewChartData()
	chartData.Labels = []string{
		"1", "2", "3",
	}
	chartData.Datasets = []*charts.Dataset{
		charts.NewDataset(
			"Some Data",
			[]float64{25, 40, 30},
		),
		charts.NewDataset(
			"Another Set",
			[]float64{25, 50, -10},
		),
	}

	chart := charts.NewScatterChart("#chart", chartData).
		WithHeight(250).
		WithColors([]string{"red", "green"}).
		Render()
	temp := 4
	for i := 0; i < 100; i++ {
		go func(i interface{}) {
			val := rand.Intn(3) + 2*i.(int)
			println(i, "sleeping for", val)
			time.Sleep(time.Duration(val) * time.Second)
			newLabel := strconv.Itoa(temp)
			actionCond := rand.Intn(4)
			switch actionCond {
			case 0:
				chart.RemoveDataPoint(rand.Int())
			case 1:
				chart.PopDataPoint()
			case 2:
				chart.AppendDataPoint([]float64{float64(rand.Intn(1000)), float64(rand.Intn(1000))}, newLabel)
			case 3:
				chart.AddDataPoint([]float64{float64(rand.Intn(200)), float64(rand.Intn(200))}, newLabel, rand.Intn(200))
			}
			temp++
			println(temp)
		}(i)
	}

	println("is this async?")
}

Output 6:

Alt text

Disclaimer

I'm still a big Go noob, and so I don't know the proper way to manage releases and dependencies yet. I'll try to figure it out soon!

Contributions

Any contributions are welcome. :)

Changelog

here when available

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BarChart

type BarChart struct {
	*js.Object
}

func (*BarChart) AddDataPoint

func (chart *BarChart) AddDataPoint(values []float64, label string, index int)

func (*BarChart) AddDataSelectListener

func (chart *BarChart) AddDataSelectListener(fn eventListenerCallback)

AddDataSelectListener is a helper function to allow users to quickly set a data-select event. This allows users to access the index, value, and label of any particular data point!

func (*BarChart) AddEventListener

func (chart *BarChart) AddEventListener(eventName string, fn eventListenerCallback)

func (*BarChart) AppendDataPoint

func (chart *BarChart) AppendDataPoint(values []float64, label string)

func (*BarChart) HideAverages

func (chart *BarChart) HideAverages()

func (*BarChart) HideSums

func (chart *BarChart) HideSums()

func (*BarChart) PopDataPoint

func (chart *BarChart) PopDataPoint()

func (*BarChart) RemoveDataPoint

func (chart *BarChart) RemoveDataPoint(index int)

func (*BarChart) ShowAverages

func (chart *BarChart) ShowAverages()

func (*BarChart) ShowSums

func (chart *BarChart) ShowSums()

func (*BarChart) UpdateValues

func (chart *BarChart) UpdateValues(updateValues *UpdateValuesArgs)

type BarChartArgs

type BarChartArgs struct {
	*js.Object
	Parent         string              `js:"parent"`
	Title          string              `js:"title"`
	Data           *ChartData          `js:"data"`
	Type           string              `js:"type"`
	Height         int                 `js:"height"`
	Colors         []string            `js:"colors"`
	XAxisMode      string              `js:"x_axis_mode"`
	YAxisMode      string              `js:"y_axis_mode"`
	IsSeries       int                 `js:"is_series"`
	IsNavigable    int                 `js:"is_navigable"`
	FormatTooltipX func(string) string `js:"format_tooltip_x"`
	FormatTooltipY func(string) string `js:"format_tooltip_y"`
}

func NewBarChart

func NewBarChart(parent string, data *ChartData) *BarChartArgs

func (*BarChartArgs) Render

func (chartArgs *BarChartArgs) Render() *BarChart

func (*BarChartArgs) SetBton

func (chartArgs *BarChartArgs) SetBton(key string, val bool)

func (*BarChartArgs) SetIsNavigable

func (chartArgs *BarChartArgs) SetIsNavigable(val bool) *BarChartArgs

func (*BarChartArgs) SetIsSeries

func (chartArgs *BarChartArgs) SetIsSeries(val bool) *BarChartArgs

func (*BarChartArgs) SetXAxisMode

func (chartArgs *BarChartArgs) SetXAxisMode(mode string) *BarChartArgs

func (*BarChartArgs) SetYAxisMode

func (chartArgs *BarChartArgs) SetYAxisMode(mode string) *BarChartArgs

func (*BarChartArgs) WithColors

func (chartArgs *BarChartArgs) WithColors(colors []string) *BarChartArgs

func (*BarChartArgs) WithFormatTooltipX

func (chartArgs *BarChartArgs) WithFormatTooltipX(callback func(string) string) *BarChartArgs

func (*BarChartArgs) WithFormatTooltipY

func (chartArgs *BarChartArgs) WithFormatTooltipY(callback func(string) string) *BarChartArgs

func (*BarChartArgs) WithHeight

func (chartArgs *BarChartArgs) WithHeight(height int) *BarChartArgs

func (*BarChartArgs) WithTitle

func (chartArgs *BarChartArgs) WithTitle(title string) *BarChartArgs

type ChartData

type ChartData struct {
	*js.Object
	Labels         []string         `js:"labels"`
	Datasets       []*Dataset       `js:"datasets"`
	SpecificValues []*SpecificValue `js:"specific_values"`
}

ChartData represents the "data" object that is passed into any of the charts except Heatmap. https://frappe.github.io/charts/ Ctrl + F "let data ="

func NewChartData

func NewChartData() *ChartData

NewChartData just instantiates a ChartData JS object.

type DataSelectEvent

type DataSelectEvent struct {
	*js.Object
	Value interface{} `js:"value"`
	Label interface{} `js:"label"`
	Index int         `js:"index"`
}

type Dataset

type Dataset struct {
	*js.Object
	Title  string        `js:"title"`
	Values []interface{} `js:"values"`
}

Dataset represents a single dataset of the JS object 'data'. https://frappe.github.io/charts/ Ctrl + F "datasets". Wrap this inside a dataset array.

func NewDataset

func NewDataset(title string, values []float64) (dataset *Dataset)

NewDataset allows us to quickly create Dataset objects with the required values.

type HeatmapArgs

type HeatmapArgs struct {
	*js.Object
	Parent          string                 `js:"parent"`
	Data            map[string]interface{} `js:"data"`
	Type            string                 `js:"type"`
	Height          int                    `js:"height"`
	DiscreteDomains int                    `js:"discrete_domains"`
	Start           *js.Object             `js:"start"` // TODO
	LegendColors    []string               `js:"legend_colors"`
}

func NewHeatmapChart

func NewHeatmapChart(parent string, data map[string]int) *HeatmapArgs

func (*HeatmapArgs) Render

func (chartArgs *HeatmapArgs) Render()

func (*HeatmapArgs) SetDiscreteDomain

func (chartArgs *HeatmapArgs) SetDiscreteDomain(val bool) *HeatmapArgs

func (*HeatmapArgs) WithHeight

func (chartArgs *HeatmapArgs) WithHeight(height int) *HeatmapArgs

func (*HeatmapArgs) WithLegendColors

func (chartArgs *HeatmapArgs) WithLegendColors(colors []string) *HeatmapArgs

type LineChart

type LineChart struct {
	*js.Object
}

func (*LineChart) AddDataPoint

func (chart *LineChart) AddDataPoint(values []float64, label string, index int)

AddDataPoint allows us to add a data point to anywhere in the chart.

func (*LineChart) AppendDataPoint

func (chart *LineChart) AppendDataPoint(values []float64, label string)

AppendDataPoint calls add_data_point without an index (which defaults to the end).

func (*LineChart) HideAverages

func (chart *LineChart) HideAverages()

HideAverages simply hides the averages displayed using ShowAverages.

func (*LineChart) PopDataPoint

func (chart *LineChart) PopDataPoint()

PopDataPoint calls remove_data_point without arguments, which defaults to removing the element at index 0.

func (*LineChart) RemoveDataPoint

func (chart *LineChart) RemoveDataPoint(index int)

RemoveDataPoint allows users to remove a data point anywhere in the array.

func (*LineChart) ShowAverages

func (chart *LineChart) ShowAverages()

ShowAverages calls show_averages which makes a new horizontal line representing the average for every dataset.

func (*LineChart) UpdateValues

func (chart *LineChart) UpdateValues(updateValues *UpdateValuesArgs)

UpdateValues allows us to batch update the values of the chart. Make sure to pass in the original labels if you want to keep the structure of your chart. This should be improved.

type LineChartArgs

type LineChartArgs struct {
	*js.Object
	Parent         string              `js:"parent"`
	Title          string              `js:"title"`
	Data           *ChartData          `js:"data"`
	Type           string              `js:"type"`
	Height         int                 `js:"height"`
	Colors         []string            `js:"colors"`
	XAxisMode      string              `js:"x_axis_mode"`
	YAxisMode      string              `js:"y_axis_mode"`
	IsSeries       int                 `js:"is_series"`
	ShowDots       int                 `js:"show_dots"`
	Heatline       int                 `js:"heatline"`
	RegionFill     int                 `js:"region_fill"`
	FormatTooltipX func(string) string `js:"format_tooltip_x"`
	FormatTooltipY func(string) string `js:"format_tooltip_y"`
}

LineChartArgs represents the configuration arguments that can be used to instantiate a line chart.

func NewLineChart

func NewLineChart(parent string, data *ChartData) *LineChartArgs

func (*LineChartArgs) Render

func (chartArgs *LineChartArgs) Render() *LineChart

Render returns a LineChart that allows users to call the above functions.

func (*LineChartArgs) SetBton

func (chartArgs *LineChartArgs) SetBton(key string, val bool)

func (*LineChartArgs) SetHeatline

func (chartArgs *LineChartArgs) SetHeatline(val bool) *LineChartArgs

SetHeatline allows us to set heatline using a boolean instead of 1/0's.

func (*LineChartArgs) SetIsSeries

func (chartArgs *LineChartArgs) SetIsSeries(val bool) *LineChartArgs

SetIsSeries allows us to set is_series using a boolean instead of 1/0's.

func (*LineChartArgs) SetRegionFill

func (chartArgs *LineChartArgs) SetRegionFill(val bool) *LineChartArgs

SetRegionFill allows us to set region_fill using a boolean instead of 1/0's.

func (*LineChartArgs) SetShowDots

func (chartArgs *LineChartArgs) SetShowDots(val bool) *LineChartArgs

SetShowDots allows us to set show_dots using a boolean instead of 1/0's.

func (*LineChartArgs) SetXAxisMode

func (chartArgs *LineChartArgs) SetXAxisMode(mode string) *LineChartArgs

func (*LineChartArgs) SetYAxisMode

func (chartArgs *LineChartArgs) SetYAxisMode(mode string) *LineChartArgs

func (*LineChartArgs) WithColors

func (chartArgs *LineChartArgs) WithColors(colors []string) *LineChartArgs

func (*LineChartArgs) WithFormatTooltipX

func (chartArgs *LineChartArgs) WithFormatTooltipX(callback func(string) string) *LineChartArgs

func (*LineChartArgs) WithFormatTooltipY

func (chartArgs *LineChartArgs) WithFormatTooltipY(callback func(string) string) *LineChartArgs

func (*LineChartArgs) WithHeight

func (chartArgs *LineChartArgs) WithHeight(height int) *LineChartArgs

func (*LineChartArgs) WithTitle

func (chartArgs *LineChartArgs) WithTitle(title string) *LineChartArgs

type PercentageChartArgs

type PercentageChartArgs struct {
	*js.Object
	Parent string     `js:"parent"`
	Title  string     `js:"title"`
	Data   *ChartData `js:"data"`
	Type   string     `js:"type"`
	Height int        `js:"height"`
	Colors []string   `js:"colors"`
}

PercentageChartArgs represents the args needed to instantiate a percentage chart. PercentageChart does not have as many configuration arguments as other charts in frappe-charts.

func NewPercentageChart

func NewPercentageChart(parent string, data *ChartData) *PercentageChartArgs

func (*PercentageChartArgs) Render

func (chartArgs *PercentageChartArgs) Render()

Render simply renders a percentage chart without returning anything, because percentage charts don't seem to have any methods yet (in 0.0.3 frappe-charts).

func (*PercentageChartArgs) WithColors

func (chartArgs *PercentageChartArgs) WithColors(colors []string) *PercentageChartArgs

func (*PercentageChartArgs) WithHeight

func (chartArgs *PercentageChartArgs) WithHeight(height int) *PercentageChartArgs

func (*PercentageChartArgs) WithTitle

func (chartArgs *PercentageChartArgs) WithTitle(title string) *PercentageChartArgs

type PieChartArgs

type PieChartArgs struct {
	*js.Object
	Parent string     `js:"parent"`
	Title  string     `js:"title"`
	Data   *ChartData `js:"data"`
	Type   string     `js:"type"`
	Height int        `js:"height"`
	Colors []string   `js:"colors"`
}

PieChartArgs represents the args needed to instantiate a pie chart. PieChart does not have as many configuration arguments as other charts in frappe-charts.

func NewPieChart

func NewPieChart(parent string, data *ChartData) *PieChartArgs

func (*PieChartArgs) Render

func (chartArgs *PieChartArgs) Render()

Render simply renders a pie chart without returning anything, because pie charts don't seem to have any methods yet (in 0.0.3 frappe-charts).

func (*PieChartArgs) WithColors

func (chartArgs *PieChartArgs) WithColors(colors []string) *PieChartArgs

func (*PieChartArgs) WithHeight

func (chartArgs *PieChartArgs) WithHeight(height int) *PieChartArgs

func (*PieChartArgs) WithTitle

func (chartArgs *PieChartArgs) WithTitle(title string) *PieChartArgs

type ScatterChart

type ScatterChart struct {
	*js.Object
}

func (*ScatterChart) AddDataPoint

func (chart *ScatterChart) AddDataPoint(values []float64, label string, index int)

func (*ScatterChart) AppendDataPoint

func (chart *ScatterChart) AppendDataPoint(values []float64, label string)

func (*ScatterChart) HideAverages

func (chart *ScatterChart) HideAverages()

HideAverages simply hides the averages displayed using ShowAverages.

func (*ScatterChart) PopDataPoint

func (chart *ScatterChart) PopDataPoint()

PopDataPoint calls remove_data_point without arguments, which defaults to removing the element at index 0.

func (*ScatterChart) RemoveDataPoint

func (chart *ScatterChart) RemoveDataPoint(index int)

RemoveDataPoint allows users to remove a data point anywhere in the array.

func (*ScatterChart) ShowAverages

func (chart *ScatterChart) ShowAverages()

ShowAverages calls show_averages which makes a new horizontal line representing the average for every dataset.

func (*ScatterChart) UpdateValues

func (chart *ScatterChart) UpdateValues(updateValues *UpdateValuesArgs)

type ScatterChartArgs

type ScatterChartArgs struct {
	*js.Object
	Parent         string              `js:"parent"`
	Title          string              `js:"title"`
	Data           *ChartData          `js:"data"`
	Type           string              `js:"type"`
	Height         int                 `js:"height"`
	Colors         []string            `js:"colors"`
	XAxisMode      string              `js:"x_axis_mode"`
	YAxisMode      string              `js:"y_axis_mode"`
	IsSeries       int                 `js:"is_series"`
	FormatTooltipX func(string) string `js:"format_tooltip_x"`
	FormatTooltipY func(string) string `js:"format_tooltip_y"`
}

ScatterChartArgs represents the relevant arguments that are used to instantiate a scatter chart.

func NewScatterChart

func NewScatterChart(parent string, data *ChartData) *ScatterChartArgs

func (*ScatterChartArgs) Render

func (chartArgs *ScatterChartArgs) Render() *ScatterChart

Render returns a ScatterChart that allows users to call the above functions.

func (*ScatterChartArgs) SetBton

func (chartArgs *ScatterChartArgs) SetBton(key string, val bool)

func (*ScatterChartArgs) SetIsSeries

func (chartArgs *ScatterChartArgs) SetIsSeries(val bool) *ScatterChartArgs

SetIsSeries allows us to set is_series using a boolean instead of 1/0's.

func (*ScatterChartArgs) SetXAxisMode

func (chartArgs *ScatterChartArgs) SetXAxisMode(mode string) *ScatterChartArgs

func (*ScatterChartArgs) SetYAxisMode

func (chartArgs *ScatterChartArgs) SetYAxisMode(mode string) *ScatterChartArgs

func (*ScatterChartArgs) WithColors

func (chartArgs *ScatterChartArgs) WithColors(colors []string) *ScatterChartArgs

func (*ScatterChartArgs) WithFormatTooltipX

func (chartArgs *ScatterChartArgs) WithFormatTooltipX(callback func(string) string) *ScatterChartArgs

func (*ScatterChartArgs) WithFormatTooltipY

func (chartArgs *ScatterChartArgs) WithFormatTooltipY(callback func(string) string) *ScatterChartArgs

func (*ScatterChartArgs) WithHeight

func (chartArgs *ScatterChartArgs) WithHeight(height int) *ScatterChartArgs

func (*ScatterChartArgs) WithTitle

func (chartArgs *ScatterChartArgs) WithTitle(title string) *ScatterChartArgs

type SpecificValue

type SpecificValue struct {
	*js.Object
	Title    string  `js:"title"`
	LineType string  `js:"line_type"`
	Value    float64 `js:"value"`
}

SpecificValue represents a frappe-chart specific value object. https://frappe.github.io/charts/ Ctrl + F "specific_values"

func NewSpecificValue

func NewSpecificValue(title string, lineType string, value float64) *SpecificValue

NewSpecificValue is a helper to create a Specific Value JS object.

type UpdateValueSet

type UpdateValueSet struct {
	*js.Object
	Values []interface{} `js:"values"`
}

UpdateValueSet represents the JS object frappe-chart uses as parameters for chart.update_values(values, labels). e.g. { values: [1, 2, 3, 4] }

func NewUpdateValueSet

func NewUpdateValueSet(values []float64) *UpdateValueSet

NewUpdateValueSet is a helper to conveniently create an UpdateValueSet.

type UpdateValuesArgs

type UpdateValuesArgs struct {
	Values []*UpdateValueSet
	Labels []string
}

UpdateValuesArgs is a wrapper that contains the two parameters that chart.update_values(values, labels) requires. https://frappe.github.io/charts/ Ctrl + F "update_values"

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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