Code Monkey home page Code Monkey logo

chart's Introduction

Charts for Go

Basic charts in go.

This package focuses more on autoscaling, error bars, and logarithmic plots than on beautifull or marketing ready charts.

Examples

Some nice charts

Chart Types

The following chart types are implemented:

  • Strip Charts
  • Scatter / Function-Plot Charts
  • Histograms
  • Bar and Categorical Bar Charts
  • Pie/Ring Charts
  • Boxplots

Some Features

  • Axis can be linear, logarithmical, categorical or time/date axis.
  • Autoscaling with lots of options
  • Fine control of tics and labels

Output / Graphic Formats

Package chart itself provideds the charts/plots itself, the charts/plots can be output to different graphic drivers. Currently

  • txtg: ASCII art charts
  • svgg: scalable vector graphics (via github.com/ajstarks/svgo), and
  • imgg: Go image.RGBA (via code.google.com/p/draw2d/draw2d/ and code.google.com/p/freetype-go) are implemented.

For a quick overview save as xbestof.{png,svg,txt} run

  $ example/example -best

A fuller overview can be generated by

  $ example/example -All

Quirks

  • Style handling (especialy colour) is a bit of a mess .
  • Text based charts are cute. But the general graphics would be much easier without.
  • Time handling code dates back to pre Go1, it should be reworked.

chart's People

Contributors

ajstarks avatar arranubels avatar harenber avatar pwaller avatar stephen-soltesz avatar vdobler avatar wzshiming avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chart's Issues

runtime: out of memory when drawing logarithmic y axis

Hello,
I try to plot a bar chart with a logarithmic y axis, but I always get an out of memory exception in:
chart.go:569
I tried hiding the tics, limiting the max range and setting delta to a tenth of my maximum value, but it's not helping.
Do you have an idea how I can circumvent this?
Interestingly, the example logarithmic chart works.
I would be glad to provide further information if you require.

Greetings,
Alex

go get currently broken on go1.0.2

If I try to install the example, I get the following error:

$ go get -v github.com/vdobler/chart/example
github.com/vdobler/chart/imgg
# github.com/vdobler/chart/imgg
github.com/vdobler/chart/imgg/image.go:101: cannot use dpi (type int) as type float64 in function argument
github.com/vdobler/chart/imgg/image.go:110: c.FUnitToFix32 undefined (type *freetype.Context has no field or method FUnitToFix32)
github.com/vdobler/chart/imgg/image.go:110: cannot use prev (type truetype.Index) as type int32 in function argument
github.com/vdobler/chart/imgg/image.go:110: not enough arguments in call to ig.font.Kerning
github.com/vdobler/chart/imgg/image.go:112: c.FUnitToFix32 undefined (type *freetype.Context has no field or method FUnitToFix32)
github.com/vdobler/chart/imgg/image.go:112: cannot use index (type truetype.Index) as type int32 in function argument
github.com/vdobler/chart/imgg/image.go:112: not enough arguments in call to ig.font.HMetric
github.com/vdobler/chart/imgg/image.go:259: cannot use dpi (type int) as type float64 in function argument
github.com/vdobler/chart/imgg/image.go:267: c.FUnitToPixelRU undefined (type *freetype.Context has no field or method FUnitToPixelRU)
github.com/vdobler/chart/imgg/image.go:267: ig.font.UnitsPerEm undefined (type *truetype.Font has no field or method UnitsPerEm)
github.com/vdobler/chart/imgg/image.go:267: too many errors

Incorrect bitshifts

github.com/vdobler/chart/svgg/svg.go:59: suspicious shift of sg.bg.R
github.com/vdobler/chart/svgg/svg.go:59: suspicious shift of sg.bg.G
github.com/vdobler/chart/svgg/svg.go:59: suspicious shift of sg.bg.B
github.com/vdobler/chart/svgg/svg.go:60: suspicious shift of sg.bg.A
github.com/vdobler/chart/svgg/svg.go:73: suspicious shift of sg.bg.R
github.com/vdobler/chart/svgg/svg.go:73: suspicious shift of sg.bg.G
github.com/vdobler/chart/svgg/svg.go:73: suspicious shift of sg.bg.B
github.com/vdobler/chart/svgg/svg.go:73: suspicious shift of sg.bg.A

The above locations shift color.RGBA fields right by 8 (c.R >> 8). But as they are uint8s, a right shift of 8 will always yield 0. It's not obvious what these shifts are supposed to be doing.

feature request: draw lines using a continuous polygon

I'm working on an OpenGL backend for chart, and it's really obvious that some lines are composed out of lots of little lines.

Would it be possible to make a new Polygon function? Backends not implementing it yet could fall back to drawing individual lines.

BarChart wrong formatted bars

The following snippet will generate the attached wrong formatted bar chart. If more bars are used the formatting looks okay, so somehow the bar width and pos calculation for one or two datapoints is wrong.
chart_issue

func IssueChart() error {
    wuc := chart.BarChart{Title: "Weekly Data Usage"}
    wuc.XRange.Category = []string{"W1", "W2"}
    wuc.XRange.Label, wuc.YRange.Label = "Calendar Week", "Data Transfer (MB)"
    wuc.Key.Pos, wuc.Key.Cols, wuc.Key.Border = "otc", 2, -1
    wuc.YRange.ShowZero = true
    wuc.ShowVal = 0
    pos := []float64{0, 1}
    rx := []float64{100.0, 150.0}
    tx := []float64{50.0, 200.0}
    wuc.AddDataPair("RX (Download)", pos, rx,
        chart.Style{Symbol: 'o', LineColor: color.NRGBA{69, 117, 179, 0xff}, LineWidth: 2, FillColor: color.NRGBA{79, 127, 189, 0xff}})
    wuc.AddDataPair("TX (Upload)", pos, tx,
        chart.Style{Symbol: 'o', LineColor: color.NRGBA{182, 70, 67, 0xff}, LineWidth: 2, FillColor: color.NRGBA{192, 80, 77, 0xff}})
    // Save image
    igr := imgg.New(1024, 640, color.RGBA{0xff, 0xff, 0xff, 0xff}, nil, nil)
    wuc.Plot(igr)
    fh, err := os.Create("chart_issue.jpg")
    if err != nil {
        return err
    }
    err = jpeg.Encode(fh, igr.Image, nil)
    return err
}

Wrongly and inconsistently labeled points

package main

import (
	"image/color"
	"image/jpeg"
	"log"
	"os"

	"github.com/vdobler/chart"
	"github.com/vdobler/chart/imgg"
)

func main() {
	style := chart.Style{Symbol: 'o', LineColor: color.NRGBA{0x00, 0x00, 0xff, 0xff},
		FillColor: color.NRGBA{0xff, 0xff, 0xff, 0xff},
		LineStyle: chart.SolidLine, LineWidth: 2}
	c := chart.BarChart{}
	c.YRange.Label = "Total"
	c.YRange.Fixed(0, 56000, 5000)
	c.AddDataPair("Total",
		[]float64{1, 2, 3, 4, 5},
		[]float64{55954, 55653, 54100, 51527, 44034}, style)
	g := imgg.New(640, 480, color.RGBA{255, 255, 255, 255}, nil, nil)
	c.Plot(g)
	fo, err := os.Create("output.jpg")
	if err != nil {
		log.Fatal(err)
	}
	defer fo.Close()
	if err = jpeg.Encode(fo, g.Image, nil); err != nil {
		log.Fatal(err)
	}
}

Result: https://i.imgur.com/5dLCgVp.jpg

Y axis: 5000 is formatted as 5.0 k unlike all the other values (10 k, not 10.0 k, etc.)

X axis: the first label is somehow 500m (?) instead of 0 or 0.0.

Documentation issue [ absence of examples]

I am newbie to go and can't understand how to use this package. Can you please provide basic usage with some examples. Because example you provided is big and hard to understand for me :(. And when I start my own test project I have errors like this:

../../.go/src/github.com/vdobler/chart/imgg/image.go:9:2: cannot find package "github.com/golang/freetype" in any of:
    /usr/lib/go/src/github.com/golang/freetype (from $GOROOT)
    /home/kir/.go/src/github.com/golang/freetype (from $GOPATH)
../../.go/src/github.com/vdobler/chart/imgg/image.go:10:2: cannot find package "github.com/golang/freetype/truetype" in any of:
    /usr/lib/go/src/github.com/golang/freetype/truetype (from $GOROOT)
    /home/kir/.go/src/github.com/golang/freetype/truetype (from $GOPATH)
../../.go/src/github.com/vdobler/chart/imgg/image.go:11:2: cannot find package "github.com/llgcode/draw2d" in any of:
    /usr/lib/go/src/github.com/llgcode/draw2d (from $GOROOT)
    /home/kir/.go/src/github.com/llgcode/draw2d (from $GOPATH)
../../.go/src/github.com/vdobler/chart/imgg/image.go:12:2: cannot find package "github.com/llgcode/draw2d/draw2dimg" in any of:
    /usr/lib/go/src/github.com/llgcode/draw2d/draw2dimg (from $GOROOT)
    /home/kir/.go/src/github.com/llgcode/draw2d/draw2dimg (from $GOPATH)
../../.go/src/github.com/vdobler/chart/imgg/image.go:14:2: cannot find package "golang.org/x/image/draw" in any of:
    /usr/lib/go/src/golang.org/x/image/draw (from $GOROOT)
    /home/kir/.go/src/golang.org/x/image/draw (from $GOPATH)
....

License missing?

Hello

The chart package looks very interesting, but it seems to lack a license?

Problems with text overflow in Key/Legend for svg files

I copied the dumper for both png/svg. When I plot the result, the text in the legend of the svg file overflow its box

png looks good

entropy-1680123884

svg overflows

entropy-1680123884

The code I'm using for plotting is here and the minimal config for the key is here

Awesome work! I really like these charts

Status of the project

I noticed that two years have passed since last commit. Does this mean that the project is dead?

out of memory error when logarithmic Y-Axis scale includes the range from 7e-11 to 9.999e-11

I'm getting an "out of memory" error when trying to plot data on a logarithmic scale, but only when the data is within a certain range. Please look at the following:

https://jsfiddle.net/vp72e7j9/

If the data is above or below the range, the chart renders fine, however, if the data enters this range, the memory spikes and you get the error. (Watch the browser memory in Task Manager to see it spike). I'm using Firefox but it crashes in Chrome as well.

SVG PieChart broken for segments >180°

Consider

piec := chart.PieChart{Title: "testdata"}
piec.AddIntDataPair("Data1", []string{"2009", "2010", "2011"}, []int{10, 10, 45})
piec.Key.Border = -1
piec.FmtVal = chart.AbsoluteValue
dumper:=NewDumper("testfile",1,1,800,600)
defer dumper.Close()
dumper.Plot(&piec)

will give you and SVG output which looks like this (PNG is fine!).

Schnappschuss (2019-07-24 17 25 24)

Think you need a different arc when you have segments that are >180°.

Stroke should not be applied to text

the group style is applying both fill and stroke to the text. This results in blurry text. The solution is to remove:

"stroke:#000000; stroke-width:1

from the group.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.