image collector.
This commit is contained in:
parent
6fbc6caa9c
commit
ce5b36a6cb
27
_examples/image_writer/main.go
Normal file
27
_examples/image_writer/main.go
Normal 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)
|
||||||
|
}
|
|
@ -210,5 +210,9 @@ func (rr *rasterRenderer) ClearTextRotation() {
|
||||||
|
|
||||||
// Save implements the interface method.
|
// Save implements the interface method.
|
||||||
func (rr *rasterRenderer) Save(w io.Writer) error {
|
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)
|
return png.Encode(w, rr.i)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user