Skip to content

Commit

Permalink
Feat: add sunburst example (#26)
Browse files Browse the repository at this point in the history
* Feat: add sunburst example
  • Loading branch information
susiwen8 committed Mar 23, 2021
1 parent fe3950f commit c8d9898
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions examples/sunburst.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package examples

import (
"io"
"math/rand"
"os"
"strconv"

"github.com/go-echarts/go-echarts/v2/charts"
"github.com/go-echarts/go-echarts/v2/components"
"github.com/go-echarts/go-echarts/v2/opts"
)

func generateSunburstItems() []opts.SunBurstData {
items := make([]opts.SunBurstData, 0)
for i := 0; i < 7; i++ {
items = append(items, opts.SunBurstData{
Value: rand.Float64(),
Name: "parent-" + strconv.Itoa(i),
Children: []*opts.SunBurstData{
{
Value: rand.Float64(),
Name: "child-" + strconv.Itoa(i),
},
},
})
}
return items
}

func sunburstBase() *charts.Sunburst {
sunburst := charts.NewSunburst()
sunburst.SetGlobalOptions(
charts.WithTitleOpts(opts.Title{Title: "basic sunburst example"}),
)
sunburst.AddSeries("sunburst", generateSunburstItems())
return sunburst
}

type SunburstExample struct{}

func (SunburstExample) Examples() {
page := components.NewPage()
page.AddCharts(
sunburstBase(),
)
f, err := os.Create("examples/html/sunburst.html")
if err != nil {
panic(err)
}
page.Render(io.MultiWriter(f))

}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func main() {
examples.ThemeriverExamples{},
examples.ThemeExamples{},
examples.WordcloudExamples{},
examples.SunburstExample{},
}

for _, e := range examplers {
Expand Down

0 comments on commit c8d9898

Please sign in to comment.