diff --git a/README.md b/README.md index 6cafc68..22d3205 100644 --- a/README.md +++ b/README.md @@ -49,12 +49,25 @@ func writeFile(file string, buf []byte) error { } func chartsRender() ([]byte, error) { - d, err := charts.Render(charts.ChartOption{ - Type: charts.ChartOutputPNG, - Title: charts.TitleOption{ - Text: "Line", + d, err := charts.LineRender([][]float64{ + { + 150, + 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", "Tue", "Wed", @@ -62,19 +75,8 @@ func chartsRender() ([]byte, error) { "Fri", "Sat", "Sun", - }), - SeriesList: charts.SeriesList{ - charts.NewSeriesFromValues([]float64{ - 150, - 230, - 224, - 218, - 135, - 147, - 260, - }), - }, - }) + })), + ) if err != nil { return nil, err } diff --git a/README_zh.md b/README_zh.md index e3747e7..ad7a4d9 100644 --- a/README_zh.md +++ b/README_zh.md @@ -49,12 +49,25 @@ func writeFile(file string, buf []byte) error { } func chartsRender() ([]byte, error) { - d, err := charts.Render(charts.ChartOption{ - Type: charts.ChartOutputPNG, - Title: charts.TitleOption{ - Text: "Line", + d, err := charts.LineRender([][]float64{ + { + 150, + 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", "Tue", "Wed", @@ -62,19 +75,8 @@ func chartsRender() ([]byte, error) { "Fri", "Sat", "Sun", - }), - SeriesList: charts.SeriesList{ - charts.NewSeriesFromValues([]float64{ - 150, - 230, - 224, - 218, - 135, - 147, - 260, - }), - }, - }) + })), + ) if err != nil { return nil, err } diff --git a/chart_option.go b/chart_option.go index 1bbf4cf..5e25873 100644 --- a/chart_option.go +++ b/chart_option.go @@ -30,6 +30,11 @@ import ( // OptionFunc option function 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 func TypeOptionFunc(t string) OptionFunc { return func(opt *ChartOption) { diff --git a/examples/basic/main.go b/examples/basic/main.go index 12c0fd6..1e7af8d 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -24,12 +24,25 @@ func writeFile(file string, buf []byte) error { } func chartsRender() ([]byte, error) { - d, err := charts.Render(charts.ChartOption{ - Type: charts.ChartOutputPNG, - Title: charts.TitleOption{ - Text: "Line", + d, err := charts.LineRender([][]float64{ + { + 150, + 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", "Tue", "Wed", @@ -37,19 +50,8 @@ func chartsRender() ([]byte, error) { "Fri", "Sat", "Sun", - }), - SeriesList: charts.SeriesList{ - charts.NewSeriesFromValues([]float64{ - 150, - 230, - 224, - 218, - 135, - 147, - 260, - }), - }, - }) + })), + ) if err != nil { return nil, err }