| 1 |
package main |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import ( |
| 6 |
"fmt" |
| 7 |
"os" |
| 8 |
|
| 9 |
"github.com/wcharczuk/go-chart/v2" |
| 10 |
) |
| 11 |
|
| 12 |
func main() { |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
graph := chart.Chart{ |
| 21 |
XAxis: chart.XAxis{ |
| 22 |
TickPosition: chart.TickPositionBetweenTicks, |
| 23 |
ValueFormatter: func(v interface{}) string { |
| 24 |
typed := v.(float64) |
| 25 |
typedDate := chart.TimeFromFloat64(typed) |
| 26 |
return fmt.Sprintf("%d-%d\n%d", typedDate.Month(), typedDate.Day(), typedDate.Year()) |
| 27 |
}, |
| 28 |
}, |
| 29 |
Series: []chart.Series{ |
| 30 |
chart.ContinuousSeries{ |
| 31 |
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, |
| 32 |
YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, |
| 33 |
}, |
| 34 |
chart.ContinuousSeries{ |
| 35 |
YAxis: chart.YAxisSecondary, |
| 36 |
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, |
| 37 |
YValues: []float64{50.0, 40.0, 30.0, 20.0, 10.0}, |
| 38 |
}, |
| 39 |
}, |
| 40 |
} |
| 41 |
|
| 42 |
f, _ := os.Create("output.png") |
| 43 |
defer f.Close() |
| 44 |
graph.Render(chart.PNG, f) |
| 45 |
} |