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/tree: add tree chart type #159

Merged
merged 10 commits into from Mar 17, 2021
Merged

Conversation

AndreZiviani
Copy link
Contributor

Tree

image

Example

package main

import (
	"os"
        "io"

	"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 main() {
    tree := charts.NewTree()
    tree.SetGlobalOptions(
        charts.WithTitleOpts(opts.Title{Title: "Tree Chart"}),
            charts.WithToolboxOpts(opts.Toolbox{
                Show: true,
                    Feature: &opts.ToolBoxFeature{
                        SaveAsImage: &opts.ToolBoxFeatureSaveAsImage{
                            Show:  true,
                            Type:  "png",
                            Title: "Download as PNG",
                        },
                    },
                }),
                charts.WithLegendOpts(opts.Legend{Show: true}),
                charts.WithTooltipOpts(opts.Tooltip{Show: true}),
	)

    chield1 := &opts.TreeData{
        Name: "test2",
        Value: 2,
    }
    chield2 := &opts.TreeData{
        Name: "test3",
        Value: 3,
    }

    children := make([]*opts.TreeData, 0)
    children = append(children, chield1)
    children = append(children, chield2)

    nodes := make([]*opts.TreeData, 0)
    nodes = append(nodes,
        opts.TreeData{
            Name: "test",
            Value: 1,
            Children: children,
        },
    )

    tree.AddSeries("tree", nodes).
        SetSeriesOptions(
            charts.WithTreeOpts(
                opts.TreeChart{
                    Layout: "orthogonal",
                    Orient: "LR",
                },
            ),
            charts.WithLabelOpts(opts.Label{Show: true, Position: "top", Color: "Black"}),
        )
    page := components.NewPage()
    page.AddCharts(tree)
    f, _ := os.Create("tree.html")
    page.Render(io.MultiWriter(f))
}

types/charts.go Outdated Show resolved Hide resolved
Koooooo-7
Koooooo-7 previously approved these changes Mar 15, 2021
charts/tree.go Outdated Show resolved Hide resolved
@Koooooo-7
Copy link
Member

Could u plz add an example at here also.

@chenjiandongx chenjiandongx self-requested a review March 17, 2021 13:29
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

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

3 participants