diff --git a/charts/tree.go b/charts/tree.go new file mode 100644 index 00000000..ec60cdf4 --- /dev/null +++ b/charts/tree.go @@ -0,0 +1,35 @@ +package charts + +import ( + "github.com/go-echarts/go-echarts/v2/opts" + "github.com/go-echarts/go-echarts/v2/render" + "github.com/go-echarts/go-echarts/v2/types" +) + +// Tree represents a Tree chart. +type Tree struct { + RectChart +} + +// Type returns the chart type. +func (Tree) Type() string { return types.Tree } + +// NewTree creates a new Tree chart instance. +func NewTree() *Tree { + c := &Tree{} + c.initBaseConfiguration() + c.Renderer = render.NewChartRender(c, c.Validate) + return c +} + +func (c *Tree) AddSeries(name string, data []opts.TreeData, options ...SeriesOpts) *Tree { + series := SingleSeries{Name: name, Type: types.Tree, Data: data} + series.configureSeriesOpts(options...) + c.MultiSeries = append(c.MultiSeries, series) + return c +} + +// Validate validates the given configuration. +func (c *Tree) Validate() { + c.Assets.Validate(c.AssetsHost) +} diff --git a/opts/charts.go b/opts/charts.go index 769a6440..f7ed0e1a 100644 --- a/opts/charts.go +++ b/opts/charts.go @@ -516,3 +516,13 @@ type Chart3DData struct { // The style setting of the text label in a single bar. Label *Label `json:"label,omitempty"` } + +type TreeData struct { + // Name of the data item. + Name string `json:"name,omitempty"` + + // Value of the data item. + Value int `json:"value,omitempty"` + + Children []*TreeData `json:"children,omitempty"` +} diff --git a/types/charts.go b/types/charts.go index e8f2b481..398cf96e 100644 --- a/types/charts.go +++ b/types/charts.go @@ -26,4 +26,5 @@ const ( ChartSurface3D = "surface" ChartThemeRiver = "themeRiver" ChartWordCloud = "wordCloud" + Tree = "tree" )