Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: basic sunburst chart #158

Merged
merged 4 commits into from Mar 12, 2021
Merged

Feat: basic sunburst chart #158

merged 4 commits into from Mar 12, 2021

Conversation

susiwen8
Copy link
Contributor

@susiwen8 susiwen8 commented Feb 7, 2021

Sunburst

Screen Shot 2021-02-07 at 23 53 15

API

  • WithSunburstOpts
  • NewSunburst

Example

package main

import (
	"math/rand"
	"os"

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

// generate random data for bar chart
func generateBarItems() []opts.SunBurstData {
	items := make([]opts.SunBurstData, 0)
	for i := 0; i < 7; i++ {
		items = append(items, opts.SunBurstData{
			Value: rand.Float64(),
			Name:  "11111",
			Children: []*opts.SunBurstData{
				{
					Value: rand.Float64(),
					Name:  "2222",
				},
			},
		})
	}
	return items
}

func main() {
	sunburst := charts.NewSunburst()
	sunburst.SetGlobalOptions(
		charts.WithTitleOpts((opts.Title{Title: "Sunburst"})),
	)
	sunburst.AddSeries("sunburst", generateBarItems()).SetSeriesOptions(
		charts.WithLabelOpts(
			opts.Label{
				Show:      true,
				Formatter: "12345s",
			},
		),
		charts.WithSunburstOpts(
			opts.SunburstChart{
				Animation: false,
			},
		),
	)
	// Where the magic happens
	f, _ := os.Create("test.html")
	sunburst.Render(f)
}

PS

It's better to not omitempty for bool type, because Apache ECharts has default for some nullish option. In that case, if user set false, option would be omitted, echarts would receive true, that against user wish.

types/charts.go Outdated Show resolved Hide resolved
opts/series.go Outdated Show resolved Hide resolved
opts/charts.go Outdated Show resolved Hide resolved
opts/charts.go Outdated Show resolved Hide resolved
opts/global.go Outdated Show resolved Hide resolved
charts/sunburst.go Outdated Show resolved Hide resolved
Copy link
Member

@chenjiandongx chenjiandongx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chenjiandongx chenjiandongx merged commit 012bf0e into go-echarts:master Mar 12, 2021
@susiwen8 susiwen8 deleted the sunburst branch March 12, 2021 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants