package main

import (
	"fmt"
	"os"

	"github.com/vicanso/go-charts/v2"
)

func main() {

	values := [][]float64{
		{
			2.0,
			4.9,
			7.0,
			23.2,
			25.6,
			76.7,
			135.6,
			162.2,
			32.6,
			20.0,
			6.4,
			3.3,
		},
		{
			// snip...
		},
	}

	p, err := charts.BarRender(
		values,
		charts.XAxisDataOptionFunc([]string{
			"Jan",
			"Feb",
			"Mar",
			"Apr",
			"May",
			"Jun",
			"Jul",
			"Aug",
			"Sep",
			"Oct",
			"Nov",
			"Dec",
		}),
		charts.LegendLabelsOptionFunc([]string{
			"Rainfall",
			"Evaporation",
		}, charts.PositionRight),
		charts.MarkLineOptionFunc(0, charts.SeriesMarkDataTypeAverage),
		charts.MarkPointOptionFunc(0, charts.SeriesMarkDataTypeMax,
			charts.SeriesMarkDataTypeMin),
		//custom option func
		// func(opt *charts.ChartOption) {
		// 	opt.SeriesList[0].MarkPoint = charts.NewMarkPoint(
		// 		charts.SeriesMarkDataTypeMax,
		// 		charts.SeriesMarkDataTypeMin,
		// 	)
		// 	opt.SeriesList[0].MarkLine = charts.NewMarkLine(
		// 		charts.SeriesMarkDataTypeAverage,
		// 	)
		// },
	)
	if err != nil {
		panic(err)
	}

	buf, err := p.Bytes()
	if err != nil {
		panic(err)
	}
	f, err := os.OpenFile("bar.jpg", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
	if err != nil {
		fmt.Println("创建文件失败")
	}
	defer f.Close()

	f.Write(buf)
}
