Skip to content

Instantly share code, notes, and snippets.

@horlabyc

horlabyc/main.go Secret

Created January 4, 2022 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save horlabyc/dbfb16366a7056b89db4047ab95f6c98 to your computer and use it in GitHub Desktop.
Save horlabyc/dbfb16366a7056b89db4047ab95f6c98 to your computer and use it in GitHub Desktop.
Create bar chart
package main
import (
"encoding/csv"
"log"
"os"
"sort"
"strconv"
"github.com/go-echarts/go-echarts/v2/charts"
"github.com/go-echarts/go-echarts/v2/opts"
)
func createChart(sortedData DataList) {
bar := charts.NewBar()
bar.SetGlobalOptions(charts.WithTitleOpts(opts.Title{
Title: "PC Games Sales",
Subtitle: "Best selling PC games",
}))
bar.SetXAxis([]string{
sortedData[0].Key[:4], sortedData[1].Key[:4], sortedData[2].Key[:4], sortedData[3].Key[:4],
sortedData[4].Key[:4], sortedData[5].Key[:4], sortedData[6].Key[:4],
sortedData[7].Key[:4], sortedData[8].Key[:4], sortedData[9].Key[:4],
}).AddSeries("Values", generateBarItems(sortedData))
f, _ := os.Create("games.html")
bar.Render(f)
}
func generateBarItems(data DataList) []opts.BarData {
barData := []float64{}
items := make([]opts.BarData, 0)
for i := 0; i < 10; i++ {
barData = append(barData, data[i].Value)
}
for _, v := range barData {
items = append(items, opts.BarData{Value: v})
}
return items
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment