2017-02-03 14:26:53 -05:00
|
|
|
package main
|
|
|
|
|
2019-09-10 00:02:48 -04:00
|
|
|
//go:generate go run main.go
|
|
|
|
|
2017-02-03 14:26:53 -05:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"log"
|
|
|
|
"os"
|
2017-05-12 20:12:23 -04:00
|
|
|
|
2019-09-10 00:02:48 -04:00
|
|
|
"github.com/wcharczuk/go-chart"
|
2017-02-03 14:26:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var b float64
|
|
|
|
b = 1000
|
|
|
|
|
|
|
|
ts1 := chart.ContinuousSeries{ //TimeSeries{
|
2018-10-11 20:20:44 -04:00
|
|
|
Name: "Time Series",
|
2017-02-03 14:26:53 -05:00
|
|
|
XValues: []float64{10 * b, 20 * b, 30 * b, 40 * b, 50 * b, 60 * b, 70 * b, 80 * b},
|
|
|
|
YValues: []float64{1.0, 2.0, 30.0, 4.0, 50.0, 6.0, 7.0, 88.0},
|
|
|
|
}
|
|
|
|
|
|
|
|
ts2 := chart.ContinuousSeries{ //TimeSeries{
|
|
|
|
Style: chart.Style{
|
|
|
|
StrokeColor: chart.GetDefaultColor(1),
|
|
|
|
},
|
|
|
|
|
|
|
|
XValues: []float64{10 * b, 20 * b, 30 * b, 40 * b, 50 * b, 60 * b, 70 * b, 80 * b},
|
|
|
|
YValues: []float64{15.0, 52.0, 30.0, 42.0, 50.0, 26.0, 77.0, 38.0},
|
|
|
|
}
|
|
|
|
|
|
|
|
graph := chart.Chart{
|
|
|
|
|
|
|
|
XAxis: chart.XAxis{
|
|
|
|
Name: "The XAxis",
|
|
|
|
ValueFormatter: chart.TimeMinuteValueFormatter, //TimeHourValueFormatter,
|
|
|
|
},
|
|
|
|
|
|
|
|
YAxis: chart.YAxis{
|
2019-09-10 00:02:48 -04:00
|
|
|
Name: "The YAxis",
|
2017-02-03 14:26:53 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
Series: []chart.Series{
|
|
|
|
ts1,
|
|
|
|
ts2,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer := bytes.NewBuffer([]byte{})
|
|
|
|
err := graph.Render(chart.PNG, buffer)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fo, err := os.Create("output.png")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := fo.Write(buffer.Bytes()); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|