制作一些 Echart图时,一直翻阅 Echarts官方文档API 。这次总结在这里,以后可以方便自己。如果大家感觉不错的话,也可以收藏,到时候随时可以回来查看,希望能帮到大家!! 总的来说,我自己把最主要的分为如下这几大类:
- title 标题
- legend 图例
- xAxis x轴
- yAxis y轴
- dataZoom 区域缩放
- tooltip 提示框
- visualMap 视觉映射组件
- geo 地图组件
option = {
title: {
text: "Main Title",
subtext: "Sub Title",
left: "center",
top: "center",
textStyle: {
fontSize: 30,
color: 'red'
},
subtextStyle: {
fontSize: 20
},
itemGap: 10,
backgroundColor: 'transparent',
},
legend: {
type: 'scroll',
orient: 'vertical',
right: 10,
top: 20,
bottom: 20,
selectedMode: true,
inactiveColor: '#ccc',
selected: {
'系列1': true,
'系列2': false
},
textStyle:{
},
formatter: function (name) {
return echarts.format.truncateText(name, 40, '14px Microsoft Yahei', '…');
},
tooltip: {
show: true,
position: function (pos, params, dom, rect, size) {
var obj = {top: 60};
obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 5;
return obj;
},
formatter: function (params, ticket, callback) {
$.get('detail?name=' + params.name, function (content) {
callback(ticket, toHTML(content));
});
return 'Loading';
}
},
icon: 'circle',
data: [{
name: '系列1',
icon: 'circle',
textStyle: {
color: 'red'
}
}],
series: [{
data: [],
type: '',
}]
},
xAxis: {
axisLabel: {
interval: 'auto'
rotate: 45,
margin: 8,
formatter: function (value, index) {
var date = new Date(value);
var texts = [(date.getMonth() + 1), date.getDate()];
if (index === 0) {
texts.unshift(date.getYear());
}
return texts.join('/');
},
textStyle: {
color: function (value, index) {
return value >= 0 ? 'green' : 'red';
}
}
},
splitLine:{
show: true
}
}
yAxis: {
show: false,
axisLabel: {
interval: 'auto'
rotate: 45,
margin: 8,
formatter: function (value, index) {
var date = new Date(value);
var texts = [(date.getMonth() + 1), date.getDate()];
if (index === 0) {
texts.unshift(date.getYear());
}
return texts.join('/');
},
textStyle: {
color: function (value, index) {
return value >= 0 ? 'green' : 'red';
}
}
},
splitLine:{
show: true
}
}
dataZoom: [{
type: "inside",
disabled: true,
filterMode: 'filter',
start: 50,
end: 100,
startValue: 0,
endValue: 10,
minSpan: 0,
maxSpan: 100,
minValueSpan: 3600 * 24 * 1000 * 5,
maxValueSpan: 3600 * 24 * 1000 * 5,
orient: 'horizontal',
zoomLock: true,
zoomOnMouseWheel: true,
moveOnMouseMove: true,
moveOnMouseWheel: true,
},{
type: "slider",
show: true,
backgroundColor: 'rgba(47,69,84,0)',
handleIcon: '',
start: 50,
end: 100,
startValue: 0,
endValue: 10,
minSpan: 0,
maxSpan: 100,
minValueSpan: 3600 * 24 * 1000 * 5,
maxValueSpan: 3600 * 24 * 1000 * 5,
orient: 'horizontal',
zoomLock: true,
}],
visualMap: [
{
type: 'continuous',
show: true,
min: 0,
max: 100,
range: [0, 50000],
calculable: true,
realtime: true,
orient: 'vertical',
inverse: 'false',
precision: 2,
itemWidth: 20,
itemHeight: 140,
align: 'auto',
text: ['High', 'Low'],
dimension: 1,
...
},
{
type: 'piecewise',
...
}
],
}
tooltip 提示框组件: 可以设置在全局,即 tooltip 可以设置在坐标系中,即 grid.tooltip、polar.tooltip、single.tooltip
可以设置在系列中,即 series.tooltip
可以设置在系列的每个数据项中,即 series.data.tooltip
|