• Stars
    star
    1,407
  • Rank 33,429 (Top 0.7 %)
  • Language
    JavaScript
  • License
    BSD 3-Clause "New...
  • Created about 8 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Liquid Fill Chart for Apache ECharts

Liquid Fill Chart

Liquid Fill Chart plugin for Apache ECharts, which is usually used to represent data in percentage.

Rendering Results

Install ECharts

To use ECharts plugins, you need to include the plugin JavaScript file after ECharts file.

<script src='echarts.js'></script>
<script src='echarts-liquidfill.js'></script>

ECharts can be downloaded at GitHub dist directory or Download page of Official Website (in Chinese).

NOTE

The minimum package of ECharts required by LiquidFill Chart is simple version on GitHub, or selecting nothing in online builder (in Chinese). If you need other chart types or components in your other chart, you should include them accordingly.

Install echarts-liquidfill with npm

# install echarts as peer dependency
npm install echarts
npm install echarts-liquidfill

NOTE:

echarts-liquidfill@3 is compitable with echarts@5 echarts-liquidfill@2 is compitable with echarts@4

Import:

import * as echarts from 'echarts';
import 'echarts-liquidfill'

Or:

import * as echarts from 'echarts/core';
import 'echarts-liquidfill'

Here is the basic example on CodeSandbox

Download echarts-liquidfill from GitHub

You may download the lastest ECharts files on ECharts official site and download this plugin in dist directory.

Note that if you need tooltip for Liquid Fill Chart, you need the complete ECharts version. Otherwise, the simple version will be competent.

Important Notes

Omitted normal

Since ECharts v4.0.0, normal is no longer needed for itemStyle or label.

Flatten textStyle

Since ECharts v3.7.0, textStyle option is flatten, so that series.label[normal|emphasis].textStyle.xxx is now can be written in series.label[normal|emphasis].textStyle. This is supported from echarts-liquidfill v1.0.6. So if you found examples with textStyle in old demo, don't be too surprised.

Quick Start

Here are some common uses:

To ask a question, you may fork Liquid Fill Chart Example on Gallery and copy your code there. Then you may open an issue in this project.

Examples

A Simple Example

To create a Liquid Fill Chart, you need to have a series with type of 'liquidFill'. A basic option may be:

var option = {
    series: [{
        type: 'liquidFill',
        data: [0.6]
    }]
};

A simple liquid fill chart

Run

Multiple Waves

It is easy to create a liquid fill chart will multiple waves, either to represent multiple data, or to improve the visual effect of the chart.

var option = {
    series: [{
        type: 'liquidFill',
        data: [0.6, 0.5, 0.4, 0.3]
    }]
};

This creates a chart wit waves at position of 60%, 50%, 40%, and 30%.

Multiple waves

Run

Color and Opacity

To set colors for liquid fill chart series, set color to be an array of colors. To set opacity, use itemStyle.opacity and itemStyle.emphasis.opacity for normal style and hover style.

var option = {
    series: [{
        type: 'liquidFill',
        data: [0.5, 0.4, 0.3],
        color: ['red', '#0f0', 'rgb(0, 0, 255)'],
        itemStyle: {
                opacity: 0.6
        },
        emphasis: {
            itemStyle: {
                opacity: 0.9
            }
        }
    }]
};

Color and opacity

Run

You may also set the color and opacity of a single data item by:

var option = {
    series: [{
        type: 'liquidFill',
        data: [0.5, 0.4, {
            value: 0.3,
            itemStyle: {
                color: 'red',
                opacity: 0.6
            },
            emphasis: {
                itemStyle: {
                    opacity: 0.9
                }
            }
        }]
    }]
};

Color and opacity of a single data item

Run

Static Waves

To provent the waves from moving left or right, you may simply set waveAnimation to be false. To disable the animation of waves raising, set animationDuration and animationDurationUpdate to be 0.

var option = {
    series: [{
        type: 'liquidFill',
        waveAnimation: false,
        animationDuration: 0,
        animationDurationUpdate: 0,
        data: [0.6, 0.5, 0.4, 0.3]
    }]
};

Static waves

Run

Still Water

You may set the amplitude to be 0 to make still waves.

var option = {
    series: [{
        type: 'liquidFill',
        data: [0.6, 0.5, 0.4, 0.3],
        amplitude: 0,
        waveAnimation: 0
    }]
};

It is recommended to set waveAnimation to be false in this case to disable animation for performance consideration.

Still water

Run

Change A Single Wave

To change a single wave, overwrite the options in data item.

var option = {
    series: [{
        type: 'liquidFill',
        data: [0.6, {
            value: 0.5,
            direction: 'left',
            itemStyle: {
                color: 'red'
            }
        }, 0.4, 0.3]
    }]
};

Change a single wave

Run

Background Style

You can use backgroundStyle option to set the stroke, fill style of background shape.

var option = {
    series: [{
        type: 'liquidFill',
        data: [0.6, 0.5, 0.4, 0.3],
        backgroundStyle: {
            borderWidth: 5,
            borderColor: 'red',
            color: 'yellow'
        }
    }]
};

Change border width and color

Run

Outline Style

To hide the outline, just set outline.show to be false.

var option = {
    series: [{
        type: 'liquidFill',
        data: [0.6, 0.5, 0.4, 0.3],
        outline: {
            show: false
        }
    }]
};

No outline

Run

Shape

Shape of water fill chart. It can be:

  • one of the default symbols: 'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow';
  • 'container': a shape that fully fills the container.
  • an SVG path starting with 'path://'.
var options = [{
    series: [{
        type: 'liquidFill',
        data: [0.6, 0.5, 0.4, 0.3],
        shape: 'diamond'
    }]
}];

Diamond wave

Run

option = {
    series: [{
        type: 'liquidFill',
        data: [0.5, 0.4, 0.3, 0.2],
        shape: 'container',
        outline: {
            show: false
        }
    }]
};

Fill the container

Run

var option = {
    series: [{
        type: 'liquidFill',
        data: [0.6, 0.55, 0.4, 0.25],
        radius: '60%',
        outline: {
            show: false
        },
        backgroundStyle: {
            borderColor: '#156ACF',
            borderWidth: 1,
            shadowColor: 'rgba(0, 0, 0, 0.4)',
            shadowBlur: 20
        },
        shape: 'path://M367.855,428.202c-3.674-1.385-7.452-1.966-11.146-1.794c0.659-2.922,0.844-5.85,0.58-8.719 c-0.937-10.407-7.663-19.864-18.063-23.834c-10.697-4.043-22.298-1.168-29.902,6.403c3.015,0.026,6.074,0.594,9.035,1.728 c13.626,5.151,20.465,20.379,15.32,34.004c-1.905,5.02-5.177,9.115-9.22,12.05c-6.951,4.992-16.19,6.536-24.777,3.271 c-13.625-5.137-20.471-20.371-15.32-34.004c0.673-1.768,1.523-3.423,2.526-4.992h-0.014c0,0,0,0,0,0.014 c4.386-6.853,8.145-14.279,11.146-22.187c23.294-61.505-7.689-130.278-69.215-153.579c-61.532-23.293-130.279,7.69-153.579,69.202 c-6.371,16.785-8.679,34.097-7.426,50.901c0.026,0.554,0.079,1.121,0.132,1.688c4.973,57.107,41.767,109.148,98.945,130.793 c58.162,22.008,121.303,6.529,162.839-34.465c7.103-6.893,17.826-9.444,27.679-5.719c11.858,4.491,18.565,16.6,16.719,28.643 c4.438-3.126,8.033-7.564,10.117-13.045C389.751,449.992,382.411,433.709,367.855,428.202z',
        label: {
            position: ['38%', '40%'],
            formatter: function() {
                return 'ECharts\nLiquid Fill';
            },
            fontSize: 40,
            color: '#D94854'
        }
    }]
};

ECharts Liquid Fill

Run

Animation

Generally speaking, there are two types of animations in liquid fill charts.

The first type is initial animation, which has the effect of wave raising. The easing method of this animation is controlled with animationEasing and its duration with animationDuration.

The second type is the update animation, which is usually used when data changes and wave height changes. They are controlled with animationEasingUpdate and animationDurationUpdate.

For example, to disable the raising animation and set update animation time to be two seconds with cubicOut easing, you can use the following option:

var option = {
    series: [{
        type: 'liquidFill',
        data: [0.6, 0.5, 0.4, 0.3],
        animationDuration: 0,
        animationDurationUpdate: 2000,
        animationEasingUpdate: 'cubicOut'
    }]
};
chart.setOption(option);
setTimeout(function () {
    chart.setOption({
        series: [{
            type: 'liquidFill',
            data: [0.8, 0.6, 0.4, 0.2]
        }]
    })
}, 3000);

Update animation

Run

Change Text

By default, the text label of liquid fill chart displays percentage of the first data. For example, for a chart with data [0.6, 0.5, 0.4, 0.3], default text is 60%.

To change the text, you may use label.formatter, which can be set to a string or function.

If it is a string, {a} refers to series name, {b} to data name, and {c} to data value.

var option = {
    series: [{
        type: 'liquidFill',
        name: 'Liquid Fill',
        data: [{
            name: 'First Data',
            value: 0.6
        }, 0.5, 0.4, 0.3],
        label: {
            formatter: '{a}\n{b}\nValue: {c}',
            fontSize: 28
        }
    }]
};

Label text of this example is 'Liquid Fill\nFirst Data\nValue: 0.6'.

Label formatter as string

Run

This has the same result as using formatter as a function:

var option = {
    series: [{
        type: 'liquidFill',
        name: 'Liquid Fill',
        data: [{
            name: 'First Data',
            value: 0.6
        }, 0.5, 0.4, 0.3],
        label: {
            formatter: function(param) {
                return param.seriesName + '\n'
                    + param.name + '\n'
                    + 'Value:' + param.value;
            },
            fontSize: 28
        }
    }]
};

Run

Text position is at the center by default. label.position can be set to be 'inside', 'left', 'right', 'top', 'bottom', or horizontal and vertical positions like ['10%', '20%'], which means '10%' to the left (controlled by label.align, which can be 'left', 'center', or 'right') and '20%' to the top (controlled by label.baseline, which can be 'top', 'middle', or 'bottom').

Shadow

By default, waves and outline have shadow on them. Here's how to change them.

var option = {
    series: [{
        type: 'liquidFill',
        data: [0.6, 0.5, 0.4, 0.3],
        itemStyle: {
            shadowBlur: 0
        },
        outline: {
            borderDistance: 0,
            itemStyle: {
                borderWidth: 5,
                borderColor: '#156ACF',
                shadowBlur: 20,
                shadowColor: 'rgba(255, 0, 0, 1)'
            }
        }
    }]
};

Change shadow

Run

Tooltip

To add tooltip:

var option = {
    series: [{
        type: 'liquidFill',
        data: [0.6],
        name: 'Liquid Fill'
    }],
    tooltip: {
        show: true
    }
};

Tooltip

Run

Click Event

To add click event on waves:

chart.setOption(option);
chart.on('click', function() {
    console.log(arguments);
    // do something useful here
});

Like any other chart types, the above code will only trigger events on waves. If you want to track events on the whole canvas or specific elements, you may add listener to zrender like:

chart.getZr().on('click', function() {
       console.log(arguments);
});

Non-interactable

To make an element (e.g., a wave) non-interactable, simply set silent to be true.

var option = {
    series: [{
        type: 'liquidFill',
        data: [0.6, 0.5, 0.4, 0.3],
        silent: true
    }]
};

Run

API

Default option for liquid fill charts are:

{
    data: [],

    color: ['#294D99', '#156ACF', '#1598ED', '#45BDFF'],
    center: ['50%', '50%'],
    radius: '50%',
    amplitude: '8%',
    waveLength: '80%',
    phase: 'auto',
    period: 'auto',
    direction: 'right',
    shape: 'circle',

    waveAnimation: true,
    animationEasing: 'linear',
    animationEasingUpdate: 'linear',
    animationDuration: 2000,
    animationDurationUpdate: 1000,

    outline: {
        show: true,
        borderDistance: 8,
        itemStyle: {
            color: 'none',
            borderColor: '#294D99',
            borderWidth: 8,
            shadowBlur: 20,
            shadowColor: 'rgba(0, 0, 0, 0.25)'
        }
    },

    backgroundStyle: {
        color: '#E3F7FF'
    },

    itemStyle: {
        opacity: 0.95,
        shadowBlur: 50,
        shadowColor: 'rgba(0, 0, 0, 0.4)'
    },

    label: {
        show: true,
        color: '#294D99',
        insideColor: '#fff',
        fontSize: 50,
        fontWeight: 'bold',

        align: 'center',
        baseline: 'middle'
        position: 'inside'
    },

    emphasis: {
        itemStyle: {
            opacity: 0.8
        }
    }
}

data {(number|Object)[]}

Value of each data item should be between 0 and 1.

The data item can also be an object to configure the option for a single item.

var option = {
    series: [{
        type: 'liquidFill',
        data: [0.6, {
            value: 0.5,
            itemStyle: {
                color: 'red'
            }
        }, 0.4, 0.3]
    }]
};

This defines a chart with the second wave of red color.

color {string[]}

Wave colors.

shape {string}

Shape of water fill chart. It can be one of the default symbols: 'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow'. Or, an SVG path starting with 'path://'.

center {string[]}

Position of the chart. The first value is x position, the second one is the y position. Each of the values can be a relative value like '50%', which is relative to the smaller value of container width and height, or an absolute value like 100px.

radius {string}

Radius of the chart, which can be a relative value like '50%', which is relative to the smaller value of container width and height, or an absolute value like 100px.

amplitude {number}

Amplitude of the wave, in pixels or percentage. If it is in percentage, it's relative to the diameter.

waveLength {string|number}

Wave length of the wave, which can be a relative value like '50%', which is relative to the diameter, or an absolute value like '100px' or 100.

phase {number}

Phase of wave, in radian system. By default, it is set to be 'auto', when each wave has a phase of Math.PI / 4 larger than the previous one.

period {number|'auto'|function}

Milliseconds that it takes to move forward a wave-length. By default, it is set to be 'auto', when the wave at the front has a greater speed.

It can also be a formatter function.

var option = {
    series: [{
        type: 'liquidFill',
        data: [0.6, 0.5, 0.4, 0.3],
        radius: '70%',
        phase: 0,
        period: function (value, index) {
            // This function is called four times, each for a data item in series.
            // `value` is 0.6, 0.5, 0.4, 0.3, and `index` is 0, 1, 2, 3.
            return 2000 * index + 1000;
        }
    }]
}

direction {string}

Direction that the waves moving in, which should either be 'right', or 'left'.

waveAnimation {boolean}

Whether to enable wave from moving left or right.

animationEasing {string}

Easing methods for initial animation, when waves raise from the bottom at the beginning.

animationEasingUpdate {string}

Easing methods for other animation, for example, when data value changes and wave position changes.

animationDuration {number}

Initial animation duration, in milliseconds.

animationDurationUpdate {number}

Other animation duration, in milliseconds.

outline.show {boolean}

Whether to display outline.

outline.borderDistance {number}

Distance between border and inner circle.

outline.itemStyle.borderColor {string}

Border color.

outline.itemStyle.borderWidth {number}

Border width.

outline.itemStyle.shadowBlur {number}

Outline shadow blur size.

outline.itemStyle.shadowColor {string}

Outline shadow color.

backgroundStyle.color {string}

Background fill color.

backgroundStyle.borderWidth {string}

Background stroke line width.

backgroundStyle.borderColor {string}

Background stroke line width.

backgroundStyle.itemStyle.shadowBlur {number}

Background shadow blur size.

backgroundStyle.itemStyle.shadowColor {string}

Background shadow color.

backgroundStyle.itemStyle.opacity {number}

Background opacity.

itemStyle.opacity {number}

Wave opacity.

itemStyle.shadowBlur {number}

Wave shadow width.

itemStyle.shadowColor {string}

Wave shadow color.

emphasis.itemStyle.opacity {number}

Wave opacity when hover.

label.show {boolean}

Whether to display label text.

label.color {string}

Color of text when display on background.

label.insideColor {string}

Color of text when display on wave.

label.fontSize {number}

Label font size.

label.fontWeight {string}

Label font weight.

label.align {string}

Text align, which should be 'left', 'center', or 'right'.

label.baseline {string}

Text vertical align, which should be 'top', 'middle', or 'bottom'.

label.position {string|string[]}

Text position is at the center by default. label.position can be set to be 'inside', 'left', 'right', 'top', 'bottom', or horizontal and vertical positions like ['10%', '20%'], which means '10%' to the left and '20%' to the top.

Build

For development:

$ webpack

For release:

$ webpack -p

More Repositories

1

vue-echarts

Vue.js component for Apache ECharts™.
JavaScript
9,615
star
2

echarts-for-weixin

基于 Apache ECharts 的微信小程序图表库
JavaScript
6,880
star
3

zrender

A lightweight graphic library providing 2d draw for Apache ECharts
TypeScript
5,816
star
4

fontmin

Minify font seamlessly
JavaScript
5,545
star
5

spec

This repository contains the specifications.
4,595
star
6

echarts-gl

Extension pack for Apache ECharts, providing globe visualization and 3D plots.
JavaScript
2,554
star
7

echarts-wordcloud

Word Cloud extension based on Apache ECharts and wordcloud2.js
JavaScript
1,592
star
8

fonteditor

在线字体编辑器
JavaScript
1,297
star
9

awesome-echarts

Awesome list of Apache ECharts
1,269
star
10

veui

Enterprise UI for Vue.js.
JavaScript
1,057
star
11

esl

enterprise standard loader
JavaScript
834
star
12

react-hooks

Collection of react hooks
TypeScript
799
star
13

fontmin-app

fontmin as an OS X, Linux and Windows app
HTML
665
star
14

fecs

Front End Code Style Suite
JavaScript
643
star
15

echarts-stat

Statistics tool for Apache ECharts
HTML
570
star
16

edp

ecomfe develop platform
JavaScript
546
star
17

etpl

ETPL是一个强复用、灵活、高性能的JavaScript模板引擎,适用于浏览器端或Node环境中视图的生成。
JavaScript
496
star
18

okam

Mini program development framework
JavaScript
416
star
19

react-native-cn

407
star
20

est

EFE Styling Toolkit based on Less
Less
398
star
21

saber

移动 Web 解决方案
CSS
358
star
22

esui

enterprise simple ui library
JavaScript
340
star
23

er

enterprise ria framework
JavaScript
301
star
24

knowledge

Front-end knowledge hierarchy
CoffeeScript
236
star
25

reskript

一个帮助开发React应用的全功能命令行套件
TypeScript
210
star
26

rider

Rider 是一个基于 Stylus 与后处理器、无侵入风格的 CSS 样式工具库
CSS
205
star
27

echarts-map-tool

Map Tool for Apache ECharts
JavaScript
130
star
28

js-native

JavaScript
116
star
29

uioc

IoC Framework for us
JavaScript
115
star
30

eslint-config

eslint shareable config for efe
JavaScript
111
star
31

san-cli

A CLI Tooling based on San.js for rapid development.
JavaScript
98
star
32

san-mui

A Set of SAN Components that Implement Google's Material Design
JavaScript
95
star
33

ub-ria

RIA base for union business
JavaScript
94
star
34

react-kiss

A simple and stupid react container solution
JavaScript
85
star
35

react-suspense-boundary

A boundary component working with suspense and error
TypeScript
84
star
36

san-xui

A Set of SAN UI Components that widely used on Baidu Cloud Console
JavaScript
81
star
37

gulp-fontmin

Minify font seamlessly
JavaScript
80
star
38

echarts-optimizer

JavaScript
79
star
39

santd

San UI Toolkit for Ant Design
TypeScript
76
star
40

moye

A Simple UI Library for ZX
JavaScript
74
star
41

ecomfe.github.io

https://efe.baidu.com
JavaScript
72
star
42

react-track

A declarative, component based solution to track page views and user events with react & react-router
TypeScript
71
star
43

echarts-graph-modularity

Graph modularity extension for community detection with Apache ECharts
HTML
70
star
44

tempad-dev

Inspect panel on Figma, for everyone.
Vue
67
star
45

diffy-update

Scripts to update object or array with a diff output
JavaScript
54
star
46

gitdiff-parser

A fast and reliable git diff parser.
HTML
53
star
47

learn-graphql-cn

Learn GraphQL 中文翻译
48
star
48

standard-redux-shape

A library to help standardize your redux state shape
JavaScript
47
star
49

htmlcs

HTML Code Style
JavaScript
46
star
50

saber-showcase

使用 saber 创建的 WebApp 示例
JavaScript
41
star
51

smarty4js

a JavaScript template most like smarty, use smarty module in javascript
JavaScript
34
star
52

rebas

Node framework for Saber, base on Express
JavaScript
34
star
53

baidubce-sdk

Baidu Cloud Engine Node.js SDK
JavaScript
28
star
54

node-csshint

Csshint your css code
JavaScript
27
star
55

amd-analyzer

JavaScript
26
star
56

echarts-bmap

HTML
26
star
57

light-dls

Front-end assets and tooling for Baidu Light DLS.
Less
25
star
58

san-loader

San-Loader 是基于 webpack 的工具,允许开发者书写 San 单文件的方式来进行组件开发。
JavaScript
25
star
59

redux-optimistic-thunk

redux-thunk like dispatching with optimistic UI supported
JavaScript
25
star
60

zrender-doc

Document for zrender
JavaScript
22
star
61

grapher.js

JavaScript 3D Plot Library
JavaScript
21
star
62

redux-managed-thunk

A redux-thunk compatible middleware with managed feature to help write more controllable and reusable thunks
JavaScript
20
star
63

efe

EFE guide
20
star
64

mini-event

A simple and dedicated library to provide event related components
JavaScript
18
star
65

veui-theme-blue

a theme for VEUI
Less
18
star
66

esui-family

Online Demo and document of ESUI Family
JavaScript
18
star
67

dls-icons

Icons for Baidu Light DLS.
JavaScript
17
star
68

echarts-gallery-feedback

Official Feedback Repository for ECharts Gallery
16
star
69

edp-webserver

Package for edp webserver.
JavaScript
16
star
70

san-realworld-app

An exemplary real-world application built with San. This is a good example to discover San for beginners.
JavaScript
16
star
71

san-transition

Append transition effects for elements in san components.
JavaScript
16
star
72

node-lesslint

Less lint
JavaScript
15
star
73

ef

ef is a integration framework with er & esui
JavaScript
14
star
74

echarts-builder-web

ECharts online builder
JavaScript
14
star
75

saber-ajax

适用于移动端、promise 风格的 ajax 封装
JavaScript
13
star
76

san-anode-utils

Util Functions for San ANode
JavaScript
13
star
77

promise

A promise respecting ES standard with plenty of handy extensions
JavaScript
12
star
78

saber-env

移动端浏览器环境检测
JavaScript
12
star
79

echarts-dagre

ECharts graph layout extension using dagre.js
JavaScript
12
star
80

aop

Aspect oriented programming utilities
JavaScript
12
star
81

sublime-etpl

An ETPL syntax definition & snippets specifically for Sublime Text.
Python
12
star
82

bat-ria

RIA extensions for Brand Ads
JavaScript
11
star
83

deep-grasp

A toolkit for adopting LLM into your existing app.
TypeScript
11
star
84

ub-ria-ui

UI components for ub ria applications - standardized & implemented
JavaScript
11
star
85

edp-build

Package for edp build.
JavaScript
10
star
86

webpack-auto-cdn-plugin

Webpack plugin to automatically extract dependencies and reference them via CDN
JavaScript
10
star
87

stylelint-config

Standard stylelint config for efe team
JavaScript
10
star
88

saber-promise

适合移动端的 Promise/A+ 实现
JavaScript
10
star
89

rider-ui

基于 rider 的 UI 样式库,用于快速构建移动应用界面
CSS
9
star
90

saber-router

适用于移动端的路由控制,支持 hash, popstate
JavaScript
9
star
91

saber-scroll

为移动端页面提供区域滚动功能
JavaScript
9
star
92

blog

Blog
CSS
9
star
93

html-nest-rule

JavaScript
8
star
94

veui-docs

Documentation website for VEUI.
JavaScript
8
star
95

saber-matchmedia

移动端 matchMedia 支持
JavaScript
8
star
96

eicons

ecom public web font icons
CSS
8
star
97

query-shape

Standard utilities to manage query requests and responses
JavaScript
8
star
98

esf

EFE Style Framework
CSS
8
star
99

saber-dom

一个适用于移动端、静态函数风格的DOM工具库
JavaScript
7
star
100

svg-mixed-loader

Webpack loader resolving svg into url string and multiple component formats.
JavaScript
7
star