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

ECharts Style Settings

ECharts Style Settings

ECharts can change the color, lightness, size, etc. of graphic elements or text through style settings.


Color Theme

Starting from ECharts 4, in addition to the default theme, two built-in themes are provided: light and dark.

The usage is as follows:

Example

var

chart

=

echarts

.

init

(

dom

,

'

light

'

)

; or

var

chart

=

echarts

.

init

(

dom

,

'

dark

'

)

;

Try it »

In addition, we can also go to the official Theme Editor to select and download your favorite theme.

Currently, theme downloads provide JS and JSON versions.

If you use the JS version, you can save the JS theme code as a theme-name.js file, then reference it in the HTML, and finally use the theme in the code.

For example, in the image above we selected a theme and saved the JS code as wonderland.js.

Example

-- Import Theme --

<

script

src

=

"https://www.runoob.com/static/js/wonderland.js"

script

...

//

After the HTML imports the wonderland.js file, call it during initialization

var myChart = echarts.init

(

dom,

'wonderland'

)

;

//

...

Try it »

If the theme is saved as a JSON file, you can load and register it yourself.

For example, in the image above we selected a theme and saved the JSON code as wonderland.json.

Example

//

The theme name is wonderland

$.getJSON

(

'wonderland.json'

,

function

(

themeJSON

)

{

    echarts.registerTheme

(

'wonderland'

, themeJSON

)

    var myChart = echarts.init

(

dom,

'wonderland'

)

;

}

)

;

Try it »

**Note:** We used $.getJSON, so jQuery must be imported.


Color Palette

The color palette can be set in option.

The color palette gives a set of colors; graphics and series automatically pick colors from it.

You can set a global color palette or a series-specific color palette.

option

=

{

   

// Global color palette.

    color

:

[

'#c23531'

,

'#2f4554'

,

'#61a0a8'

,

'#d48265'

,

'#91c7ae'

,

'#749f83'

,

 

'#ca8622'

,

'#bda29a'

,

'#6e7074'

,

'#546570'

,

'#c4ccd3'

]

,

    series

:

[

{

        type

:

'bar'

,

       

// This series's own color palette.

        color

:

[

'#dd6b66'

,

'#759aa0'

,

'#e69d87'

,

'#8dc1a9'

,

'#ea7e53'

,

'#eedd78'

,

'#73a373'

,

'#73b9bc'

,

'#7289ab'

,

'#91ca8c'

,

'#f49f42'

]

,

        ...

   

}

,

{

        type

:

'pie'

,

       

// This series's own color palette.

        color

:

[

'#37A2DA'

,

'#32C5E9'

,

'#67E0E3'

,

'#9FE6B8'

,

'#FFDB5C'

,

'#ff9f7f'

,

'#fb7293'

,

'#E062AE'

,

'#E690D1'

,

'#e7bcf3'

,

'#9d96f5'

,

'#8378EA'

,

'#96BFFF'

]

,

        ...

   

}

]

}

Global color palette example:

Example

// Global color palette.

color

:

[

'#ff0000'

,

'#00ff00'

,

'#0000ff'

,

'#d48265'

,

'#91c7ae'

,

'#749f83'

,

 

'#ca8622'

,

'#bda29a'

,

'#6e7074'

,

'#546570'

,

'#c4ccd3'

]

,

Try it »

Series color palette example:

Example

series

:

[

{

    type

:

'pie'

,

   

// This series's own color palette.

    color

:

[

'#ff0000'

,

'#00ff00'

,

'#0000ff'

,

'#9FE6B8'

,

'#FFDB5C'

,

'#ff9f7f'

,

'#fb7293'

,

'#E062AE'

,

'#E690D1'

,

'#e7bcf3'

,

'#9d96f5'

,

'#8378EA'

,

'#96BFFF'

]

,

    ...

}

]

Try it »


Direct style settings: itemStyle, lineStyle, areaStyle, label, ...

Direct style setting is a commonly used method. Throughout ECharts's option , many places can set itemStyle, lineStyle, areaStyle, label and so on. These places can directly set the color of graphic elements, line width, point size, label text, label style, etc.

Generally, ECharts's various series and components follow these naming conventions, although in different charts and components,itemStyle, label may appear in different places.

For another introduction to direct style settings, see ECharts Pie Chart.


Highlight style: emphasis

When the mouse hovers over a graphic element, a highlight style generally appears. By default, the highlight style is automatically generated from the normal style.

To customize the highlight style, you can use the emphasis property:

Example

// Highlight style.

emphasis

:

{

    itemStyle

:

{

       

// The color of the point when highlighted

        color

:

'red'

   

}

,

    label

:

{

        show

:

true

,

       

// The label text when highlighted

        formatter

:

'Label content shown when highlighted'

   

}

}

,

Try it »