vdobler / chart Goto Github PK
View Code? Open in Web Editor NEWProvide basic charts in go
License: BSD 3-Clause "New" or "Revised" License
Provide basic charts in go
License: BSD 3-Clause "New" or "Revised" License
I noticed that two years have passed since last commit. Does this mean that the project is dead?
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.
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!).
Think you need a different arc when you have segments that are >180°.
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
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.
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.
At the moment if you tried to diff images to see if you changed anything, you get a different image anyway due to the use of the rand package.
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.
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
}
Update for GO1 and gocode
Hello
The chart package looks very interesting, but it seems to lack a license?
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.
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.
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
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)
....
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.