chart

package
v0.0.0-...-42aeab8 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

README

chart -- chart package using the fync canvas library

The chart library works by reading data into a ChartBox structure, and then composing elements as needed. Elements (chart types: linechart, bar, column, scatter, attributes: axes, titles, and frames) are arranged within a scalable area defined by a top, bottom, left, right.

chart

	// Open data files
	sr, err := os.Open("sin.d")
	if err != nil {
		return err
	}
	cr, err := os.Open("cos.d")
	if err != nil {
		return err
	}

	// Read in the data
	sine, err := chart.DataRead(sr)
	if err != nil {
		return err
	}
	cosine, err := chart.DataRead(cr)
	if err != nil {
		return err
	}
	sr.Close()
	cr.Close()


	// Compose elements
	sine.Zerobased, cosine.Zerobased = false, false

	// composite two charts
	cosine.Frame(canvas, 5)
	cosine.Label(canvas, 1.5, 10)
	cosine.YAxis(canvas, 1.2, -1.0, 1.0, 1.0, "%0.2f", true)
	cosine.Color = color.RGBA{0, 128, 0, 255}
	sine.Color = color.RGBA{128, 0, 0, 255}
	cosine.Scatter(canvas, 0.75)
	sine.Scatter(canvas, 0.75)

	// two charts side by side
	sine.Left = 10
	sine.Right = sine.Left + 40
	sine.Top, cosine.Top = 30, 30
	sine.Bottom, cosine.Bottom = 10, 10

	sine.CTitle(canvas, 2, 2)
	sine.Frame(canvas, 5)
	sine.Scatter(canvas, 0.5)

	offset := 45.0
	cosine.Left = sine.Left + offset
	cosine.Right = sine.Right + offset

	cosine.CTitle(canvas, 2, 2)
	cosine.Frame(canvas, 5)
	cosine.Scatter(canvas, 0.5)

Documentation

Overview

Package chart makes charts using the fync canvas package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Grid

func Grid(canvas fc.Canvas, left, bottom, width, height, size float64, color color.RGBA)

Grid makes a grid

Types

type ChartBox

type ChartBox struct {
	Title                    string
	Data                     []NameValue
	Color                    color.RGBA
	Top, Bottom, Left, Right float64
	Minvalue, Maxvalue       float64
	Zerobased                bool
}

ChartBox holds the essential data for making a chart

func DataRead

func DataRead(r io.Reader) (ChartBox, error)

DataRead reads tab separated values into a ChartBox default values for the top, bottom, left, right (90,50,10,90) are filled in as is the default color, black

func (*ChartBox) Bar

func (c *ChartBox) Bar(canvas fc.Canvas, size float64)

Bar makes a (column) bar chart

func (*ChartBox) CTitle

func (c *ChartBox) CTitle(canvas fc.Canvas, size, offset float64)

CTitle makes a centered title

func (*ChartBox) Frame

func (c *ChartBox) Frame(canvas fc.Canvas, op float64)

Frame makes a filled frame with the specified opacity (0-100)

func (*ChartBox) HBar

func (c *ChartBox) HBar(canvas fc.Canvas, size, linespacing, textsize float64)

HBar makes a horizontal bar chart

func (*ChartBox) Label

func (c *ChartBox) Label(canvas fc.Canvas, size float64, n int)

Label draws the x axis labels

func (*ChartBox) Lego

func (c *ChartBox) Lego(canvas fc.Canvas, step float64)

Lego makes a lego/waffle chart

func (*ChartBox) Line

func (c *ChartBox) Line(canvas fc.Canvas, size float64)

Line makes a line chart

func (*ChartBox) Scatter

func (c *ChartBox) Scatter(canvas fc.Canvas, size float64)

Scatter makes a scatter chart

func (*ChartBox) YAxis

func (c *ChartBox) YAxis(canvas fc.Canvas, size, min, max, step float64, format string, gridlines bool)

YAxis makes the Y axis with optional grid lines

type NameValue

type NameValue struct {
	Label string
	Note  string
	Value float64
}

NameValue is a name,value pair

Directories

Path Synopsis
fchart -- command line chart using fc chart packages
fchart -- command line chart using fc chart packages

Jump to

Keyboard shortcuts

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