ECharts および golang テクニカル ガイド: さまざまな統計グラフを作成するための実践的なヒント。具体的なコード例が必要です。
はじめに:
準備作業:
go get -u github.com/go-echarts/go-echarts go get -u github.com/Unknwon/com go get -u github.com/gin-gonic/gin
ヒストグラムを作成します:
package main import ( "github.com/gin-gonic/gin" "github.com/go-echarts/go-echarts/v2/charts" "github.com/go-echarts/go-echarts/v2/opts" "net/http" ) func main() { r := gin.Default() r.GET("/", func(c *gin.Context) { bar := charts.NewBar() bar.SetGlobalOptions(charts.TitleOpts{Title: "柱状图示例"}) bar.AddXAxis([]string{"A", "B", "C", "D"}). AddYAxis("Series A", []opts.BarData{{Value: 10}, {Value: 20}, {Value: 30}, {Value: 40}}) bar.Render(c.Writer) }) http.ListenAndServe(":8080", r) }
折れ線グラフの作成:
package main import ( "github.com/gin-gonic/gin" "github.com/go-echarts/go-echarts/v2/charts" "github.com/go-echarts/go-echarts/v2/opts" "net/http" ) func main() { r := gin.Default() r.GET("/", func(c *gin.Context) { line := charts.NewLine() line.SetGlobalOptions(charts.TitleOpts{Title: "折线图示例"}) line.AddXAxis([]string{"A", "B", "C", "D"}). AddYAxis("Series A", []opts.LineData{{Value: 10}, {Value: 20}, {Value: 30}, {Value: 40}}) line.Render(c.Writer) }) http.ListenAndServe(":8080", r) }
円グラフの作成:
package main import ( "github.com/gin-gonic/gin" "github.com/go-echarts/go-echarts/v2/charts" "github.com/go-echarts/go-echarts/v2/opts" "net/http" ) func main() { r := gin.Default() r.GET("/", func(c *gin.Context) { pie := charts.NewPie() pie.SetGlobalOptions(charts.TitleOpts{Title: "饼图示例"}) pie.Add("Series", []opts.PieData{{Value: 10, Name: "A"}, {Value: 20, Name: "B"}, {Value: 30, Name: "C"}, {Value: 40, Name: "D"}}) pie.Render(c.Writer) }) http.ListenAndServe(":8080", r) }
レーダー チャートの作成:
package main import ( "github.com/gin-gonic/gin" "github.com/go-echarts/go-echarts/v2/charts" "github.com/go-echarts/go-echarts/v2/opts" "net/http" ) func main() { r := gin.Default() r.GET("/", func(c *gin.Context) { radar := charts.NewRadar() radar.SetGlobalOptions(charts.TitleOpts{Title: "雷达图示例"}) radar.Add("Series A", []opts.RadarIndicator{{Text: "A", Max: 100}, {Text: "B", Max: 100}, {Text: "C", Max: 100}, {Text: "D", Max: 100}}). Add("Series B", []opts.RadarIndicator{{Text: "E", Max: 100}, {Text: "F", Max: 100}, {Text: "G", Max: 100}, {Text: "H", Max: 100}}) radar.Render(c.Writer) }) http.ListenAndServe(":8080", r) }
概要:
以上がECharts と golang テクニカル ガイド: さまざまな統計グラフを作成するための実践的なヒントの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。