Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ECharts Sunburst Chart

ECharts Sunburst Chart

A sunburst chart (Sunburst) consists of multiple layers of ring charts. In the data structure, the inner ring is the parent of the outer ring. Therefore, it can show the proportion of parts to the whole like a pie chart, and also show hierarchical relationships like a treemap.

Creating a sunburst chart in ECharts is simple: just declare the type as sunburst in the series configuration. The data structure is declared as a tree structure; see the simple example below:

Example

var

option

=

{

    series

:

{

        type

:

'sunburst'

,

        data

:

[

{

            name

:

'A'

,

            value

:

10

,

            children

:

[

{

                value

:

3

,

                name

:

'Aa'

           

}

,

{

                value

:

5

,

                name

:

'Ab'

           

}

]

       

}

,

{

            name

:

'B'

,

            children

:

[

{

                name

:

'Ba'

,

                value

:

4

           

}

,

{

                name

:

'Bb'

,

                value

:

2

           

}

]

       

}

,

{

            name

:

'C'

,

            value

:

3

       

}

]

   

}

}

;

Try it »


Color and other style adjustments

By default, the global color palette is used to assign colors to the innermost layer, and the other layers share the color of their parent element.

In a sunburst chart, the color of a sector block can be set in the following three ways:

The priority of the above three is from high to low; that is, a sector block with series.data.itemStyle configured will override the settings of series.levels.itemStyle and series.itemStyle.

Below, we set the overall color to gray #aaa and the innermost color to blue blue, and set the two blocks Aa and B to red red.

Example

var

option

=

{

    series

:

{

        type

:

'sunburst'

,

        data

:

[

{

            name

:

'A'

,

            value

:

10

,

            children

:

[

{

                value

:

3

,

                name

:

'Aa'

,

                itemStyle

:

{

                    color

:

'red'

               

}

           

}

,

{

                value

:

5

,

                name

:

'Ab'

           

}

]

       

}

,

{

            name

:

'B'

,

            children

:

[

{

                name

:

'Ba'

,

                value

:

4

           

}

,

{

                name

:

'Bb'

,

                value

:

2

           

}

]

,

            itemStyle

:

{

                color

:

'red'

           

}

       

}

,

{

            name

:

'C'

,

            value

:

3

       

}

]

,

        itemStyle

:

{

            color

:

'#aaa'

       

}

,

        levels

:

[

{

           

// Node properties reserved for data drill-down

       

}

,

{

            itemStyle

:

{

                color

:

'blue'

           

}

       

}

]

   

}

}

;

Try it »

Configuring styles by layer is a very common feature that can greatly improve configuration efficiency.


Data Drill-down

The sunburst chart supports data drill-down by default; that is, after clicking a sector block, the block's data becomes the root node, further displaying the details of that data.

After data drill-down, a graphic for returning to the previous level appears in the center of the chart; its style can be configured via levels[0].

Example

var

data

=

[

{

    name

:

'Grandpa'

,

    children

:

[

{

        name

:

'Uncle Leo'

,

        value

:

15

,

        children

:

[

{

            name

:

'Cousin Jack'

,

            value

:

2

       

}

,

{

            name

:

'Cousin Mary'

,

            value

:

5

,

            children

:

[

{

                name

:

'Jackson'

,

                value

:

2

           

}

]

       

}

,

{

            name

:

'Cousin Ben'

,

            value

:

4

       

}

]

   

}

,

{

        name

:

'Father'

,

        value

:

10

,

        children

:

[

{

            name

:

'Me'

,

            value

:

5

       

}

,

{

            name

:

'Brother Peter'

,

            value

:

1

       

}

]

   

}

]

}

,

{

    name

:

'Nancy'

,

    children

:

[

{

        name

:

'Uncle Nike'

,

        children

:

[

{

            name

:

'Cousin Betty'

,

            value

:

1

       

}

,

{

            name

:

'Cousin Jenny'

,

            value

:

2

       

}

]

   

}

]

}

]

;

option

=

{

    series

:

{

        type

:

'sunburst'

,

       

// highlightPolicy: 'ancestor',

        data

:

data

,

        radius

:

[

0

,

'90%'

]

,

        label

:

{

            rotate

:

'radial'

       

}

   

}

}

;

Try it »

If the data drill-down feature is not needed, you can disable it by setting nodeClick to false, or set it to 'link' and set data.link to the link opened when clicking the sector block.


Highlight Related Sector Blocks

The sunburst chart supports highlighting related data blocks when the mouse moves over a sector block. You can set highlightPolicy, which includes the following highlight methods:

The "highlight" mentioned above uses the emphasis style for the sector block the mouse is over, and the highlight style for other related sector blocks. Through this method, the need to highlight related data can be easily achieved.

Specifically, for the configuration:

itemStyle: {

    color: 'yellow',

    borderWidth: 2,

    emphasis: {

        color: 'red'

    },

    highlight: {

        color: 'orange'

    },

    downplay: {

        color: '#ccc'

    }

}

highlightPolicy is 'descendant':

Example

option =

{

    silent:

true

,

    series:

{

        radius:

[

'15%'

,

'95%'

]

,

        center:

[

'50%'

,

'60%'

]

,

        type:

'sunburst'

,

        sort: null,

        highlightPolicy:

'descendant'

,

        data:

[

{

            value:

10

,

            children:

[

{

                name:

'target'

,

                value:

4

,

                children:

[

{

                    value:

2

,

                    children:

[

{

                        value:

1

                   

}

]

               

}

,

{

                    value:

1

               

}

,

{

                    value:

0.5

               

}

]

           

}

,

{

                value:

2

           

}

]

       

}

,

{

            value:

4

,

            children:

[

{

                children:

[

{

                    value:

2

               

}

]

           

}

]

       

}

]

,

        label:

{

            normal:

{

                rotate:

'none'

,

                color:

'#fff'

           

}

       

}

,

        levels:

[

]

,

        itemStyle:

{

            color:

'yellow'

,

            borderWidth:

2

       

}

,

        emphasis:

{

            itemStyle:

{

                color:

'red'

           

}

       

}

,

        highlight:

{

            itemStyle:

{

                color:

'orange'

           

}

       

}

,

        downplay:

{

            itemStyle:

{

                color:

'#ccc'

           

}

       

}

   

}

}

;

setTimeout

(

function

(

)

{

    myChart.dispatchAction

(

{

        type:

'sunburstHighlight'

,

        targetNodeId:

'target'

   

}

)

;

}

)

;

Try it »

highlightPolicy is 'ancestor':

Example

option =

{

    silent:

true

,

    series:

{

        radius:

[

'15%'

,

'95%'

]

,

        center:

[

'50%'

,

'60%'

]

,

        type:

'sunburst'

,

        sort: null,

        highlightPolicy:

'ancestor'

,

        data:

[

{

            value:

10

,

            children:

[

{

                value:

4

,

                children:

[

{

                    value:

2

,

                    children:

[

{

                        name:

'target'

,

                        value:

1

                   

}

]

               

}

,

{

                    value:

1

               

}

,

{

                    value:

0.5

               

}

]

           

}

,

{

                value:

2

           

}

]

       

}

,

{

            value:

4

,

            children:

[

{

                children:

[

{

                    value:

2

               

}

]

           

}

]

       

}

]

,

        label:

{

            normal:

{

                rotate:

'none'

,

                color:

'#fff'

           

}

       

}

,

        levels:

[

]

,

        itemStyle:

{

            color:

'yellow'

,

            borderWidth:

2

       

}

,

        emphasis:

{

            itemStyle:

{

                color:

'red'

           

}

       

}

,

        highlight:

{

            itemStyle:

{

                color:

'orange'

           

}

       

}

,

        downplay:

{

            itemStyle:

{

                color:

'#ccc'

           

}

       

}

   

}

}

;

setTimeout

(

function

(

)

{

    myChart.dispatchAction

(

{

        type:

'sunburstHighlight'

,

        targetNodeId:

'target'

   

}

)

;

}

)

;

Try it »


More examples

For more sunburst chart configuration references:https://www.echartsjs.com/zh/option.html#series-sunburst