refactor: update examples

This commit is contained in:
vicanso 2022-03-09 20:58:37 +08:00
parent 2316689ce5
commit 1258262f2c
4 changed files with 65 additions and 54 deletions

View file

@ -49,12 +49,25 @@ func writeFile(file string, buf []byte) error {
} }
func chartsRender() ([]byte, error) { func chartsRender() ([]byte, error) {
d, err := charts.Render(charts.ChartOption{ d, err := charts.LineRender([][]float64{
Type: charts.ChartOutputPNG, {
Title: charts.TitleOption{ 150,
Text: "Line", 230,
224,
218,
135,
147,
260,
}, },
XAxis: charts.NewXAxisOption([]string{ },
// output type
charts.PNGTypeOption(),
// title
charts.TitleOptionFunc(charts.TitleOption{
Text: "Line",
}),
// x axis
charts.XAxisOptionFunc(charts.NewXAxisOption([]string{
"Mon", "Mon",
"Tue", "Tue",
"Wed", "Wed",
@ -62,19 +75,8 @@ func chartsRender() ([]byte, error) {
"Fri", "Fri",
"Sat", "Sat",
"Sun", "Sun",
}), })),
SeriesList: charts.SeriesList{ )
charts.NewSeriesFromValues([]float64{
150,
230,
224,
218,
135,
147,
260,
}),
},
})
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -49,12 +49,25 @@ func writeFile(file string, buf []byte) error {
} }
func chartsRender() ([]byte, error) { func chartsRender() ([]byte, error) {
d, err := charts.Render(charts.ChartOption{ d, err := charts.LineRender([][]float64{
Type: charts.ChartOutputPNG, {
Title: charts.TitleOption{ 150,
Text: "Line", 230,
224,
218,
135,
147,
260,
}, },
XAxis: charts.NewXAxisOption([]string{ },
// output type
charts.PNGTypeOption(),
// title
charts.TitleOptionFunc(charts.TitleOption{
Text: "Line",
}),
// x axis
charts.XAxisOptionFunc(charts.NewXAxisOption([]string{
"Mon", "Mon",
"Tue", "Tue",
"Wed", "Wed",
@ -62,19 +75,8 @@ func chartsRender() ([]byte, error) {
"Fri", "Fri",
"Sat", "Sat",
"Sun", "Sun",
}), })),
SeriesList: charts.SeriesList{ )
charts.NewSeriesFromValues([]float64{
150,
230,
224,
218,
135,
147,
260,
}),
},
})
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -30,6 +30,11 @@ import (
// OptionFunc option function // OptionFunc option function
type OptionFunc func(opt *ChartOption) type OptionFunc func(opt *ChartOption)
// PNGTypeOption set png type of chart's output
func PNGTypeOption() OptionFunc {
return TypeOptionFunc(ChartOutputPNG)
}
// TypeOptionFunc set type of chart's output // TypeOptionFunc set type of chart's output
func TypeOptionFunc(t string) OptionFunc { func TypeOptionFunc(t string) OptionFunc {
return func(opt *ChartOption) { return func(opt *ChartOption) {

View file

@ -24,12 +24,25 @@ func writeFile(file string, buf []byte) error {
} }
func chartsRender() ([]byte, error) { func chartsRender() ([]byte, error) {
d, err := charts.Render(charts.ChartOption{ d, err := charts.LineRender([][]float64{
Type: charts.ChartOutputPNG, {
Title: charts.TitleOption{ 150,
Text: "Line", 230,
224,
218,
135,
147,
260,
}, },
XAxis: charts.NewXAxisOption([]string{ },
// output type
charts.PNGTypeOption(),
// title
charts.TitleOptionFunc(charts.TitleOption{
Text: "Line",
}),
// x axis
charts.XAxisOptionFunc(charts.NewXAxisOption([]string{
"Mon", "Mon",
"Tue", "Tue",
"Wed", "Wed",
@ -37,19 +50,8 @@ func chartsRender() ([]byte, error) {
"Fri", "Fri",
"Sat", "Sat",
"Sun", "Sun",
}), })),
SeriesList: charts.SeriesList{ )
charts.NewSeriesFromValues([]float64{
150,
230,
224,
218,
135,
147,
260,
}),
},
})
if err != nil { if err != nil {
return nil, err return nil, err
} }