是什么
echarts.js是百度前端團(tuán)隊(duì)做的基于html5-canvas的一個(gè)純Javascript的圖表庫(kù)留晚。
可以流暢的運(yùn)行在PC和移動(dòng)設(shè)備上,兼容當(dāng)前絕大部分瀏覽器(IE6/7/8/9/10/11,chrome炭序,firefox,Safari等)。
底層依賴輕量級(jí)的Canvas類庫(kù)ZRender空繁,提供直觀,生動(dòng)朱庆,可交互盛泡,可高度個(gè)性化定制的數(shù)據(jù)可視化圖表。
開源免費(fèi)商用
分為:常規(guī)用圖表庫(kù) 和 特殊圖表庫(kù)
常規(guī)的:折線圖娱颊、柱狀圖傲诵、散點(diǎn)圖、餅圖箱硕、K線圖
特殊的:用于統(tǒng)計(jì)的盒形圖拴竹,用于地理數(shù)據(jù)可視化的地圖、熱力圖剧罩、線圖栓拜,用于關(guān)系數(shù)據(jù)可視化的關(guān)系圖、treemap惠昔、旭日?qǐng)D幕与,多維數(shù)據(jù)可視化的平行坐標(biāo),還有用于 BI 的漏斗圖镇防,儀表盤啦鸣,并且支持圖與圖之間的混搭。
圖表是采用 canvas 進(jìn)行渲染繪制的来氧,所以诫给,可以設(shè)置 靜態(tài)屬性 和 綁定內(nèi)置事件
- 靜態(tài)屬性配置香拉,可以查看 下面的
echarts 常用配置表
和 官方 api - 事件綁定分為兩種:用戶鼠標(biāo)操作 和 操作 echarts 組件事件
用戶鼠標(biāo)操作 ,如 'click'中狂、'dblclick'凫碌、'mousedown'、'mousemove'吃型、'mouseup'证鸥、'mouseover'、'mouseout'勤晚、'globalout'枉层、'contextmenu' 事件。
操作 echarts 組件赐写,如在切換圖例開關(guān)時(shí)觸發(fā)的 'legendselectchanged' 事件)鸟蜡,數(shù)據(jù)區(qū)域縮放時(shí)觸發(fā)的 'datazoom' 事件等等。
下面看一個(gè)簡(jiǎn)單的應(yīng)用
第一個(gè)應(yīng)用
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>第一個(gè) ECharts 實(shí)例</title>
<!-- 引入 echarts.js -->
<script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>
</head>
<body>
<!-- 為ECharts準(zhǔn)備一個(gè)具備大型ρ(寬高)的Dom -->
<div id="main" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
// 基于準(zhǔn)備好的dom揉忘,初始化echarts實(shí)例
var myChart = echarts.init(document.getElementById('main'));
// 指定圖表的配置項(xiàng)和數(shù)據(jù)
var option = {
title: {
text: '第一個(gè) ECharts 實(shí)例'
},
tooltip: {},
legend: {
data: ['銷量']
},
xAxis: {
data: ["襯衫", "羊毛衫", "雪紡衫", "褲子", "高跟鞋", "襪子"]
},
yAxis: {},
series: [{
name: '銷量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
};
// 使用剛指定的配置項(xiàng)和數(shù)據(jù)顯示圖表。
myChart.setOption(option);
</script>
</body>
</html>
在 Vue 中使用
let vm = new Vue({
data: {
},
mounted() {
// 繪制圖表
this.$nextTick(function () {
this.lineEchart();
});
},
methods: {
// 定義函數(shù)
pieEchart() {
var _this = this;
var myChart = echarts.init(document.getElementById("pieChart"));
// 繪制圖表
myChart.setOption({
backgroundColor: "#033792",
tooltip: {
trigger: "item",
formatter: "{a} <br/>端铛 : {c} (111jvhv%)",
},
visualMap: {
show: false,
min: 80,
max: 600,
inRange: {
colorLightness: [0, 1],
},
},
series: [
{
name: "",
type: "pie",
radius: "80%",
center: ["56%", "50%"],
data: _this.dataSummaryView.sort(function (a, b) {
return a.value - b.value;
}),
roseType: "radius",
label: {
color: "rgba(90, 123, 184, 1)",
},
labelLine: {
lineStyle: {
color: "rgba(90, 123, 184, 1)",
},
smooth: 0.2,
length: 10,
length2: 20,
},
itemStyle: {
color: "rgb(206,113,105)",
shadowBlur: 200,
shadowColor: "rgba(0, 0, 0, 0.5)",
},
animationType: "scale",
animationEasing: "elasticOut",
animationDelay: function (idx) {
return Math.random() * 200;
},
},
],
});
},
lineEchart() {
var myChart = echarts.init(document.getElementById("lineChart"));
var data = this.dataTodayView; // 獲取數(shù)據(jù)
var nameList = data.map(function (item) {
return item["name"];
});
var valueList = data.map(function (item) {
return item["value"];
});
// 繪制圖表
myChart.setOption({
backgroundColor: "#033792",
// Make gradient line here
visualMap: [
{
show: false,
type: "continuous",
seriesIndex: 0,
min: 0,
max: 400,
},
],
tooltip: {
trigger: "axis",
},
xAxis: [
{
axisLine: {
lineStyle: {
color: "rgba(90, 123, 184, 1)",
},
},
data: nameList,
},
],
yAxis: [
{
axisLine: {
lineStyle: {
color: "rgba(90, 123, 184, 1)",
},
},
splitLine: { show: false },
},
],
grid: [
{
bottom: "15%",
},
{
top: "0%",
},
],
series: [
{
type: "line",
showSymbol: false,
data: valueList,
},
],
});
}
}
})
echarts 常用配置表
theme = {
// 全圖默認(rèn)背景
// backgroundColor: 'rgba(0,0,0,0)',
// 默認(rèn)色板
color: ['#ff7f50','#87cefa','#da70d6','#32cd32','#6495ed',
'#ff69b4','#ba55d3','#cd5c5c','#ffa500','#40e0d0',
'#1e90ff','#ff6347','#7b68ee','#00fa9a','#ffd700',
'#6699FF','#ff6666','#3cb371','#b8860b','#30e0e0'],
// 圖表標(biāo)題
title: {
x: 'left', // 水平安放位置泣矛,默認(rèn)為左對(duì)齊,可選為:
// 'center' | 'left' | 'right'
// | {number}(x坐標(biāo)禾蚕,單位px)
y: 'top', // 垂直安放位置您朽,默認(rèn)為全圖頂端,可選為:
// 'top' | 'bottom' | 'center'
// | {number}(y坐標(biāo)换淆,單位px)
//textAlign: null // 水平對(duì)齊方式哗总,默認(rèn)根據(jù)x設(shè)置自動(dòng)調(diào)整
backgroundColor: 'rgba(0,0,0,0)',
borderColor: '#ccc', // 標(biāo)題邊框顏色
borderWidth: 0, // 標(biāo)題邊框線寬,單位px倍试,默認(rèn)為0(無(wú)邊框)
padding: 5, // 標(biāo)題內(nèi)邊距讯屈,單位px,默認(rèn)各方向內(nèi)邊距為5县习,
// 接受數(shù)組分別設(shè)定上右下左邊距涮母,同css
itemGap: 10, // 主副標(biāo)題縱向間隔,單位px躁愿,默認(rèn)為10哈蝇,
textStyle: {
fontSize: 18,
fontWeight: 'bolder',
color: '#333' // 主標(biāo)題文字顏色
},
subtextStyle: {
color: '#aaa' // 副標(biāo)題文字顏色
}
},
// 圖例
legend: {
orient: 'horizontal', // 布局方式,默認(rèn)為水平布局攘已,可選為:
// 'horizontal' | 'vertical'
x: 'center', // 水平安放位置,默認(rèn)為全圖居中怜跑,可選為:
// 'center' | 'left' | 'right'
// | {number}(x坐標(biāo)样勃,單位px)
y: 'top', // 垂直安放位置吠勘,默認(rèn)為全圖頂端,可選為:
// 'top' | 'bottom' | 'center'
// | {number}(y坐標(biāo)峡眶,單位px)
backgroundColor: 'rgba(0,0,0,0)',
borderColor: '#ccc', // 圖例邊框顏色
borderWidth: 0, // 圖例邊框線寬剧防,單位px,默認(rèn)為0(無(wú)邊框)
padding: 5, // 圖例內(nèi)邊距辫樱,單位px峭拘,默認(rèn)各方向內(nèi)邊距為5,
// 接受數(shù)組分別設(shè)定上右下左邊距狮暑,同css
itemGap: 10, // 各個(gè)item之間的間隔鸡挠,單位px,默認(rèn)為10搬男,
// 橫向布局時(shí)為水平間隔拣展,縱向布局時(shí)為縱向間隔
itemWidth: 20, // 圖例圖形寬度
itemHeight: 14, // 圖例圖形高度
textStyle: {
color: '#333' // 圖例文字顏色
}
},
// 值域
dataRange: {
orient: 'vertical', // 布局方式,默認(rèn)為垂直布局缔逛,可選為:
// 'horizontal' | 'vertical'
x: 'left', // 水平安放位置备埃,默認(rèn)為全圖左對(duì)齊,可選為:
// 'center' | 'left' | 'right'
// | {number}(x坐標(biāo)褐奴,單位px)
y: 'bottom', // 垂直安放位置按脚,默認(rèn)為全圖底部,可選為:
// 'top' | 'bottom' | 'center'
// | {number}(y坐標(biāo)敦冬,單位px)
backgroundColor: 'rgba(0,0,0,0)',
borderColor: '#ccc', // 值域邊框顏色
borderWidth: 0, // 值域邊框線寬辅搬,單位px,默認(rèn)為0(無(wú)邊框)
padding: 5, // 值域內(nèi)邊距匪补,單位px伞辛,默認(rèn)各方向內(nèi)邊距為5,
// 接受數(shù)組分別設(shè)定上右下左邊距夯缺,同css
itemGap: 10, // 各個(gè)item之間的間隔蚤氏,單位px,默認(rèn)為10踊兜,
// 橫向布局時(shí)為水平間隔竿滨,縱向布局時(shí)為縱向間隔
itemWidth: 20, // 值域圖形寬度,線性漸變水平布局寬度為該值 * 10
itemHeight: 14, // 值域圖形高度捏境,線性漸變垂直布局高度為該值 * 10
splitNumber: 5, // 分割段數(shù)于游,默認(rèn)為5,為0時(shí)為線性漸變
color:['#1e90ff','#f0ffff'],//顏色
//text:['高','低'], // 文本垫言,默認(rèn)為數(shù)值文本
textStyle: {
color: '#333' // 值域文字顏色
}
},
toolbox: {
orient: 'horizontal', // 布局方式贰剥,默認(rèn)為水平布局,可選為:
// 'horizontal' | 'vertical'
x: 'right', // 水平安放位置,默認(rèn)為全圖右對(duì)齊只泼,可選為:
// 'center' | 'left' | 'right'
// | {number}(x坐標(biāo)魁淳,單位px)
y: 'top', // 垂直安放位置趁猴,默認(rèn)為全圖頂端桨昙,可選為:
// 'top' | 'bottom' | 'center'
// | {number}(y坐標(biāo)丽已,單位px)
color : ['#1e90ff','#22bb22','#4b0082','#d2691e'],
backgroundColor: 'rgba(0,0,0,0)', // 工具箱背景顏色
borderColor: '#ccc', // 工具箱邊框顏色
borderWidth: 0, // 工具箱邊框線寬驾孔,單位px哼勇,默認(rèn)為0(無(wú)邊框)
padding: 5, // 工具箱內(nèi)邊距瓶盛,單位px最欠,默認(rèn)各方向內(nèi)邊距為5,
// 接受數(shù)組分別設(shè)定上右下左邊距惩猫,同css
itemGap: 10, // 各個(gè)item之間的間隔芝硬,單位px,默認(rèn)為10帆锋,
// 橫向布局時(shí)為水平間隔吵取,縱向布局時(shí)為縱向間隔
itemSize: 16, // 工具箱圖形寬度
featureImageIcon : {}, // 自定義圖片icon
featureTitle : {
mark : '輔助線開關(guān)',
markUndo : '刪除輔助線',
markClear : '清空輔助線',
dataZoom : '區(qū)域縮放',
dataZoomReset : '區(qū)域縮放后退',
dataView : '數(shù)據(jù)視圖',
lineChart : '折線圖切換',
barChart : '柱形圖切換',
restore : '還原',
saveAsImage : '保存為圖片'
}
},
// 提示框
tooltip: {
trigger: 'item', // 觸發(fā)類型,默認(rèn)數(shù)據(jù)觸發(fā)锯厢,見下圖皮官,可選為:'item' | 'axis'
showDelay: 20, // 顯示延遲,添加顯示延遲可以避免頻繁切換实辑,單位ms
hideDelay: 100, // 隱藏延遲捺氢,單位ms
transitionDuration : 0.4, // 動(dòng)畫變換時(shí)間,單位s
backgroundColor: 'rgba(0,0,0,0.7)', // 提示背景顏色剪撬,默認(rèn)為透明度為0.7的黑色
borderColor: '#333', // 提示邊框顏色
borderRadius: 4, // 提示邊框圓角摄乒,單位px,默認(rèn)為4
borderWidth: 0, // 提示邊框線寬残黑,單位px馍佑,默認(rèn)為0(無(wú)邊框)
padding: 5, // 提示內(nèi)邊距,單位px梨水,默認(rèn)各方向內(nèi)邊距為5拭荤,
// 接受數(shù)組分別設(shè)定上右下左邊距,同css
axisPointer : { // 坐標(biāo)軸指示器疫诽,坐標(biāo)軸觸發(fā)有效
type : 'line', // 默認(rèn)為直線舅世,可選為:'line' | 'shadow'
lineStyle : { // 直線指示器樣式設(shè)置
color: '#48b',
width: 2,
type: 'solid'
},
shadowStyle : { // 陰影指示器樣式設(shè)置
width: 'auto', // 陰影大小
color: 'rgba(150,150,150,0.3)' // 陰影顏色
}
},
textStyle: {
color: '#fff'
}
},
// 區(qū)域縮放控制器
dataZoom: {
orient: 'horizontal', // 布局方式,默認(rèn)為水平布局奇徒,可選為:
// 'horizontal' | 'vertical'
// x: {number}, // 水平安放位置雏亚,默認(rèn)為根據(jù)grid參數(shù)適配,可選為:
// {number}(x坐標(biāo)摩钙,單位px)
// y: {number}, // 垂直安放位置罢低,默認(rèn)為根據(jù)grid參數(shù)適配,可選為:
// {number}(y坐標(biāo)胖笛,單位px)
// width: {number}, // 指定寬度奕短,橫向布局時(shí)默認(rèn)為根據(jù)grid參數(shù)適配
// height: {number}, // 指定高度宜肉,縱向布局時(shí)默認(rèn)為根據(jù)grid參數(shù)適配
backgroundColor: 'rgba(0,0,0,0)', // 背景顏色
dataBackgroundColor: '#eee', // 數(shù)據(jù)背景顏色
fillerColor: 'rgba(144,197,237,0.2)', // 填充顏色
handleColor: 'rgba(70,130,180,0.8)' // 手柄顏色
},
// 網(wǎng)格
grid: {
x: 80,
y: 60,
x2: 80,
y2: 60,
// width: {totalWidth} - x - x2,
// height: {totalHeight} - y - y2,
backgroundColor: 'rgba(0,0,0,0)',
borderWidth: 1,
borderColor: '#ccc'
},
// 類目軸
categoryAxis: {
position: 'bottom', // 位置
nameLocation: 'end', // 坐標(biāo)軸名字位置,支持'start' | 'end'
boundaryGap: true, // 類目起始和結(jié)束兩端空白策略
axisLine: { // 坐標(biāo)軸線
show: true, // 默認(rèn)顯示翎碑,屬性show控制顯示與否
lineStyle: { // 屬性lineStyle控制線條樣式
color: '#48b',
width: 2,
type: 'solid'
}
},
axisTick: { // 坐標(biāo)軸小標(biāo)記
show: true, // 屬性show控制顯示與否,默認(rèn)不顯示
interval: 'auto',
// onGap: null,
inside : false, // 控制小標(biāo)記是否在grid里
length :5, // 屬性length控制線長(zhǎng)
lineStyle: { // 屬性lineStyle控制線條樣式
color: '#333',
width: 1
}
},
axisLabel: { // 坐標(biāo)軸文本標(biāo)簽之斯,詳見axis.axisLabel
show: true,
interval: 'auto',
rotate: 0,
margin: 8,
// formatter: null,
textStyle: { // 其余屬性默認(rèn)使用全局文本樣式日杈,詳見TEXTSTYLE
color: '#333'
}
},
splitLine: { // 分隔線
show: true, // 默認(rèn)顯示,屬性show控制顯示與否
// onGap: null,
lineStyle: { // 屬性lineStyle(詳見lineStyle)控制線條樣式
color: ['#ccc'],
width: 1,
type: 'solid'
}
},
splitArea: { // 分隔區(qū)域
show: false, // 默認(rèn)不顯示佑刷,屬性show控制顯示與否
// onGap: null,
areaStyle: { // 屬性areaStyle(詳見areaStyle)控制區(qū)域樣式
color: ['rgba(250,250,250,0.3)','rgba(200,200,200,0.3)']
}
}
},
// 數(shù)值型坐標(biāo)軸默認(rèn)參數(shù)
valueAxis: {
position: 'left', // 位置
nameLocation: 'end', // 坐標(biāo)軸名字位置莉擒,支持'start' | 'end'
nameTextStyle: {}, // 坐標(biāo)軸文字樣式,默認(rèn)取全局樣式
boundaryGap: [0, 0], // 數(shù)值起始和結(jié)束兩端空白策略
splitNumber: 5, // 分割段數(shù)瘫絮,默認(rèn)為5
axisLine: { // 坐標(biāo)軸線
show: true, // 默認(rèn)顯示涨冀,屬性show控制顯示與否
lineStyle: { // 屬性lineStyle控制線條樣式
color: '#48b',
width: 2,
type: 'solid'
}
},
axisTick: { // 坐標(biāo)軸小標(biāo)記
show: false, // 屬性show控制顯示與否,默認(rèn)不顯示
inside : false, // 控制小標(biāo)記是否在grid里
length :5, // 屬性length控制線長(zhǎng)
lineStyle: { // 屬性lineStyle控制線條樣式
color: '#333',
width: 1
}
},
axisLabel: { // 坐標(biāo)軸文本標(biāo)簽麦萤,詳見axis.axisLabel
show: true,
rotate: 0,
margin: 8,
// formatter: null,
textStyle: { // 其余屬性默認(rèn)使用全局文本樣式鹿鳖,詳見TEXTSTYLE
color: '#333'
}
},
splitLine: { // 分隔線
show: true, // 默認(rèn)顯示,屬性show控制顯示與否
lineStyle: { // 屬性lineStyle(詳見lineStyle)控制線條樣式
color: ['#ccc'],
width: 1,
type: 'solid'
}
},
splitArea: { // 分隔區(qū)域
show: false, // 默認(rèn)不顯示壮莹,屬性show控制顯示與否
areaStyle: { // 屬性areaStyle(詳見areaStyle)控制區(qū)域樣式
color: ['rgba(250,250,250,0.3)','rgba(200,200,200,0.3)']
}
}
},
polar : {
center : ['50%', '50%'], // 默認(rèn)全局居中
radius : '75%',
startAngle : 90,
splitNumber : 5,
name : {
show: true,
textStyle: { // 其余屬性默認(rèn)使用全局文本樣式翅帜,詳見TEXTSTYLE
color: '#333'
}
},
axisLine: { // 坐標(biāo)軸線
show: true, // 默認(rèn)顯示,屬性show控制顯示與否
lineStyle: { // 屬性lineStyle控制線條樣式
color: '#ccc',
width: 1,
type: 'solid'
}
},
axisLabel: { // 坐標(biāo)軸文本標(biāo)簽命满,詳見axis.axisLabel
show: false,
textStyle: { // 其余屬性默認(rèn)使用全局文本樣式涝滴,詳見TEXTSTYLE
color: '#333'
}
},
splitArea : {
show : true,
areaStyle : {
color: ['rgba(250,250,250,0.3)','rgba(200,200,200,0.3)']
}
},
splitLine : {
show : true,
lineStyle : {
width : 1,
color : '#ccc'
}
}
},
// 柱形圖默認(rèn)參數(shù)
bar: {
barMinHeight: 0, // 最小高度改為0
// barWidth: null, // 默認(rèn)自適應(yīng)
barGap: '30%', // 柱間距離,默認(rèn)為柱形寬度的30%胶台,可設(shè)固定值
barCategoryGap : '20%', // 類目間柱形距離歼疮,默認(rèn)為類目間距的20%,可設(shè)固定值
itemStyle: {
normal: {
// color: '各異',
barBorderColor: '#fff', // 柱條邊線
barBorderRadius: 0, // 柱條邊線圓角诈唬,單位px韩脏,默認(rèn)為0
barBorderWidth: 1, // 柱條邊線線寬,單位px讯榕,默認(rèn)為1
label: {
show: false
// position: 默認(rèn)自適應(yīng)骤素,水平布局為'top',垂直布局為'right'愚屁,可選為
// 'inside'|'left'|'right'|'top'|'bottom'
// textStyle: null // 默認(rèn)使用全局文本樣式济竹,詳見TEXTSTYLE
}
},
emphasis: {
// color: '各異',
barBorderColor: 'rgba(0,0,0,0)', // 柱條邊線
barBorderRadius: 0, // 柱條邊線圓角,單位px霎槐,默認(rèn)為0
barBorderWidth: 1, // 柱條邊線線寬送浊,單位px,默認(rèn)為1
label: {
show: false
// position: 默認(rèn)自適應(yīng)丘跌,水平布局為'top'袭景,垂直布局為'right'唁桩,可選為
// 'inside'|'left'|'right'|'top'|'bottom'
// textStyle: null // 默認(rèn)使用全局文本樣式,詳見TEXTSTYLE
}
}
}
},
// 折線圖默認(rèn)參數(shù)
line: {
itemStyle: {
normal: {
// color: 各異,
label: {
show: false
// position: 默認(rèn)自適應(yīng)耸棒,水平布局為'top'荒澡,垂直布局為'right',可選為
// 'inside'|'left'|'right'|'top'|'bottom'
// textStyle: null // 默認(rèn)使用全局文本樣式与殃,詳見TEXTSTYLE
},
lineStyle: {
width: 2,
type: 'solid',
shadowColor : 'rgba(0,0,0,0)', //默認(rèn)透明
shadowBlur: 5,
shadowOffsetX: 3,
shadowOffsetY: 3
}
},
emphasis: {
// color: 各異,
label: {
show: false
// position: 默認(rèn)自適應(yīng)单山,水平布局為'top',垂直布局為'right'幅疼,可選為
// 'inside'|'left'|'right'|'top'|'bottom'
// textStyle: null // 默認(rèn)使用全局文本樣式米奸,詳見TEXTSTYLE
}
}
},
//smooth : false,
//symbol: null, // 拐點(diǎn)圖形類型
symbolSize: 2, // 拐點(diǎn)圖形大小
//symbolRotate : null, // 拐點(diǎn)圖形旋轉(zhuǎn)控制
showAllSymbol: false // 標(biāo)志圖形默認(rèn)只有主軸顯示(隨主軸標(biāo)簽間隔隱藏策略)
},
// K線圖默認(rèn)參數(shù)
k: {
// barWidth : null // 默認(rèn)自適應(yīng)
// barMaxWidth : null // 默認(rèn)自適應(yīng)
itemStyle: {
normal: {
color: '#fff', // 陽(yáng)線填充顏色
color0: '#00aa11', // 陰線填充顏色
lineStyle: {
width: 1,
color: '#ff3200', // 陽(yáng)線邊框顏色
color0: '#00aa11' // 陰線邊框顏色
}
},
emphasis: {
// color: 各異,
// color0: 各異
}
}
},
// 散點(diǎn)圖默認(rèn)參數(shù)
scatter: {
//symbol: null, // 圖形類型
symbolSize: 4, // 圖形大小,半寬(半徑)參數(shù)爽篷,當(dāng)圖形為方向或菱形則總寬度為symbolSize * 2
//symbolRotate : null, // 圖形旋轉(zhuǎn)控制
large: false, // 大規(guī)模散點(diǎn)圖
largeThreshold: 2000,// 大規(guī)模閥值悴晰,large為true且數(shù)據(jù)量>largeThreshold才啟用大規(guī)模模式
itemStyle: {
normal: {
// color: 各異,
label: {
show: false
// position: 默認(rèn)自適應(yīng),水平布局為'top'逐工,垂直布局為'right'铡溪,可選為
// 'inside'|'left'|'right'|'top'|'bottom'
// textStyle: null // 默認(rèn)使用全局文本樣式,詳見TEXTSTYLE
}
},
emphasis: {
// color: '各異'
label: {
show: false
// position: 默認(rèn)自適應(yīng)钻弄,水平布局為'top'佃却,垂直布局為'right',可選為
// 'inside'|'left'|'right'|'top'|'bottom'
// textStyle: null // 默認(rèn)使用全局文本樣式窘俺,詳見TEXTSTYLE
}
}
}
},
// 雷達(dá)圖默認(rèn)參數(shù)
radar : {
itemStyle: {
normal: {
// color: 各異,
label: {
show: false
},
lineStyle: {
width: 2,
type: 'solid'
}
},
emphasis: {
// color: 各異,
label: {
show: false
}
}
},
//symbol: null, // 拐點(diǎn)圖形類型
symbolSize: 2 // 可計(jì)算特性參數(shù)饲帅,空數(shù)據(jù)拖拽提示圖形大小
//symbolRotate : null, // 圖形旋轉(zhuǎn)控制
},
// 餅圖默認(rèn)參數(shù)
pie: {
center : ['50%', '50%'], // 默認(rèn)全局居中
radius : [0, '75%'],
clockWise : false, // 默認(rèn)逆時(shí)針
startAngle: 90,
minAngle: 0, // 最小角度改為0
selectedOffset: 10, // 選中是扇區(qū)偏移量
itemStyle: {
normal: {
// color: 各異,
borderColor: '#fff',
borderWidth: 1,
label: {
show: true,
position: 'outer'
// textStyle: null // 默認(rèn)使用全局文本樣式,詳見TEXTSTYLE
},
labelLine: {
show: true,
length: 20,
lineStyle: {
// color: 各異,
width: 1,
type: 'solid'
}
}
},
emphasis: {
// color: 各異,
borderColor: 'rgba(0,0,0,0)',
borderWidth: 1,
label: {
show: false
// position: 'outer'
// textStyle: null // 默認(rèn)使用全局文本樣式瘤泪,詳見TEXTSTYLE
},
labelLine: {
show: false,
length: 20,
lineStyle: {
// color: 各異,
width: 1,
type: 'solid'
}
}
}
}
},
map: {
mapType: 'china', // 各省的mapType暫時(shí)都用中文
mapLocation: {
x : 'center',
y : 'center'
// width // 自適應(yīng)
// height // 自適應(yīng)
},
showLegendSymbol : true, // 顯示圖例顏色標(biāo)識(shí)(系列標(biāo)識(shí)的小圓點(diǎn))灶泵,存在legend時(shí)生效
itemStyle: {
normal: {
// color: 各異,
borderColor: '#fff',
borderWidth: 1,
areaStyle: {
color: '#ccc'//rgba(135,206,250,0.8)
},
label: {
show: false,
textStyle: {
color: 'rgba(139,69,19,1)'
}
}
},
emphasis: { // 也是選中樣式
// color: 各異,
borderColor: 'rgba(0,0,0,0)',
borderWidth: 1,
areaStyle: {
color: 'rgba(255,215,0,0.8)'
},
label: {
show: false,
textStyle: {
color: 'rgba(139,69,19,1)'
}
}
}
}
},
force : {
// 數(shù)據(jù)map到圓的半徑的最小值和最大值
minRadius : 10,
maxRadius : 20,
density : 1.0,
attractiveness : 1.0,
// 初始化的隨機(jī)大小位置
initSize : 300,
// 向心力因子,越大向心力越大
centripetal : 1,
// 冷卻因子
coolDown : 0.99,
// 分類里如果有樣式會(huì)覆蓋節(jié)點(diǎn)默認(rèn)樣式
itemStyle: {
normal: {
// color: 各異,
label: {
show: false
// textStyle: null // 默認(rèn)使用全局文本樣式对途,詳見TEXTSTYLE
},
nodeStyle : {
brushType : 'both',
color : '#f08c2e',
strokeColor : '#5182ab'
},
linkStyle : {
strokeColor : '#5182ab'
}
},
emphasis: {
// color: 各異,
label: {
show: false
// textStyle: null // 默認(rèn)使用全局文本樣式赦邻,詳見TEXTSTYLE
},
nodeStyle : {},
linkStyle : {}
}
}
},
chord : {
radius : ['65%', '75%'],
center : ['50%', '50%'],
padding : 2,
sort : 'none', // can be 'none', 'ascending', 'descending'
sortSub : 'none', // can be 'none', 'ascending', 'descending'
startAngle : 90,
clockWise : false,
showScale : false,
showScaleText : false,
itemStyle : {
normal : {
label : {
show : true
// textStyle: null // 默認(rèn)使用全局文本樣式,詳見TEXTSTYLE
},
lineStyle : {
width : 0,
color : '#000'
},
chordStyle : {
lineStyle : {
width : 1,
color : '#666'
}
}
},
emphasis : {
lineStyle : {
width : 0,
color : '#000'
},
chordStyle : {
lineStyle : {
width : 2,
color : '#333'
}
}
}
}
},
island: {
r: 15,
calculateStep: 0.1 // 滾輪可計(jì)算步長(zhǎng) 0.1 = 10%
},
markPoint : {
symbol: 'pin', // 標(biāo)注類型
symbolSize: 10, // 標(biāo)注大小实檀,半寬(半徑)參數(shù)惶洲,當(dāng)圖形為方向或菱形則總寬度為symbolSize * 2
//symbolRotate : null, // 標(biāo)注旋轉(zhuǎn)控制
itemStyle: {
normal: {
// color: 各異,
// borderColor: 各異, // 標(biāo)注邊線顏色膳犹,優(yōu)先于color
borderWidth: 2, // 標(biāo)注邊線線寬恬吕,單位px,默認(rèn)為1
label: {
show: true,
position: 'inside' // 可選為'left'|'right'|'top'|'bottom'
// textStyle: null // 默認(rèn)使用全局文本樣式须床,詳見TEXTSTYLE
}
},
emphasis: {
// color: 各異
label: {
show: true
// position: 'inside' // 'left'|'right'|'top'|'bottom'
// textStyle: null // 默認(rèn)使用全局文本樣式铐料,詳見TEXTSTYLE
}
}
}
},
markLine : {
// 標(biāo)線起始和結(jié)束的symbol介紹類型,如果都一樣,可以直接傳string
symbol: ['circle', 'arrow'],
// 標(biāo)線起始和結(jié)束的symbol大小钠惩,半寬(半徑)參數(shù)柒凉,當(dāng)圖形為方向或菱形則總寬度為symbolSize * 2
symbolSize: [2, 4],
// 標(biāo)線起始和結(jié)束的symbol旋轉(zhuǎn)控制
//symbolRotate : null,
itemStyle: {
normal: {
// color: 各異, // 標(biāo)線主色,線色篓跛,symbol主色
// borderColor: 隨color, // 標(biāo)線symbol邊框顏色膝捞,優(yōu)先于color
borderWidth: 2, // 標(biāo)線symbol邊框線寬,單位px愧沟,默認(rèn)為2
label: {
show: false,
// 可選為 'start'|'end'|'left'|'right'|'top'|'bottom'
position: 'inside',
textStyle: { // 默認(rèn)使用全局文本樣式绑警,詳見TEXTSTYLE
color: '#333'
}
},
lineStyle: {
// color: 隨borderColor, // 主色,線色央渣,優(yōu)先級(jí)高于borderColor和color
// width: 隨borderWidth, // 優(yōu)先于borderWidth
type: 'solid',
shadowColor : 'rgba(0,0,0,0)', //默認(rèn)透明
shadowBlur: 5,
shadowOffsetX: 3,
shadowOffsetY: 3
}
},
emphasis: {
// color: 各異
label: {
show: false
// position: 'inside' // 'left'|'right'|'top'|'bottom'
// textStyle: null // 默認(rèn)使用全局文本樣式,詳見TEXTSTYLE
},
lineStyle : {}
}
}
},
textStyle: {
decoration: 'none',
fontFamily: 'Arial, Verdana, sans-serif',
fontFamily2: '微軟雅黑', // IE8- 字體模糊并且不支持不同字體混排渴频,額外指定一份
fontSize: 12,
fontStyle: 'normal',
fontWeight: 'normal'
},
// 默認(rèn)標(biāo)志圖形類型列表
symbolList : [
'circle', 'rectangle', 'triangle', 'diamond',
'emptyCircle', 'emptyRectangle', 'emptyTriangle', 'emptyDiamond'
],
loadingText : 'Loading...',
// 可計(jì)算特性配置芽丹,孤島,提示顏色
calculable: false, // 默認(rèn)關(guān)閉可計(jì)算特性
calculableColor: 'rgba(255,165,0,0.6)', // 拖拽提示邊框顏色
calculableHolderColor: '#ccc', // 可計(jì)算占位提示顏色
nameConnector: ' & ',
valueConnector: ' : ',
animation: true,
animationThreshold: 2500, // 動(dòng)畫元素閥值卜朗,產(chǎn)生的圖形原素超過(guò)2500不出動(dòng)畫
addDataAnimation: true, // 動(dòng)態(tài)數(shù)據(jù)接口是否開啟動(dòng)畫效果
animationDuration: 2000,
animationEasing: 'ExponentialOut' //BounceOut
}
API
- 官網(wǎng)地址:https://echarts.apache.org/zh/index.html
- runbook: https://www.runoob.com/echarts/echarts-tutorial.html
總結(jié)
Echarts 是 web 端圖表頁(yè)面的首選框架拔第,需要通過(guò)實(shí)踐不斷的熟悉框架的 api 。
通常工作中遇到問(wèn)題场钉,需要注意以下幾點(diǎn)
- dom 加載的問(wèn)題蚊俺,是否先加載 dom 在渲染 echarts
- 數(shù)據(jù)格式的問(wèn)題, 注意數(shù)據(jù)格式的嵌套關(guān)系
- 注意配置項(xiàng)嵌套關(guān)系不要弄混了
筆記方式總結(jié)逛万,目的常用api 學(xué)習(xí)回顧