image collector.

This commit is contained in:
Will Charczuk 2016-08-27 14:23:55 -07:00
parent 6fbc6caa9c
commit ce5b36a6cb
2 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,27 @@
package main
import (
"fmt"
"log"
"github.com/wcharczuk/go-chart"
)
func main() {
graph := chart.Chart{
Series: []chart.Series{
chart.ContinuousSeries{
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
},
},
}
collector := &chart.ImageWriter{}
graph.Render(chart.PNG, collector)
image, err := collector.Image()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Final Image: %dx%d\n", image.Bounds().Size().X, image.Bounds().Size().Y)
}

View File

@ -210,5 +210,9 @@ func (rr *rasterRenderer) ClearTextRotation() {
// Save implements the interface method.
func (rr *rasterRenderer) Save(w io.Writer) error {
if typed, isTyped := w.(RGBACollector); isTyped {
typed.SetRGBA(rr.i)
return nil
}
return png.Encode(w, rr.i)
}