如何使用左边的dataZoom控制3个图形的数据变化
配置项如下
var data0 = splitData([
['2013/3/1', 15,235,23],
['2013/3/2', 25,54,23],
['2013/3/3', 23,235,23],
['2013/3/4', 8,9,200],
['2013/3/5', 22,232,22],
['2013/3/6', 23,234,23],
['2013/3/7', 23,232,23],
['2013/3/8', 23,231,23],
['2013/3/9', 23,231,23],
['2013/3/10', 23,231,23],
['2013/3/11', 23,231,22],
['2013/3/12', 89,22,22],
['2013/3/13', 22,226,22],
['2013/3/14', 22,227,22],
['2013/3/15', 22,22,250],
['2013/3/18', 22,224,22],
['2013/3/19', 22,225,22],
['2013/3/20', 22,231,22],
['2013/3/21', 23,232,23],
['2013/3/22', 2,232,23],
['2013/3/23', 2,231,23],
['2013/3/24', 2,232,23],
['2013/3/25', 23,232,23],
['2013/3/26', 23,229,22],
['2013/3/27', 22,230,289],
['2013/3/28', 22,22,22],
['2013/3/29', 22,223,22],
['2013/3/30', 22,223,28]
]);
function splitData(rawData) {
var categoryData = [];
var values = [];
var values2 = [];
var values3 = [];
for (var i = 0; i < rawData.length; i++) {
categoryData.push(rawData[i][0]);
values.push(rawData[i][1]);
values2.push(rawData[i][2]);
values3.push(rawData[i][3]);
}
return {
categoryData: categoryData,
values: values,
values2:values2,
values3:values3
};
}
option = {
baseOption:{
backgroundColor: '#fff',
title: [
{text:''},
{
text:'今天请假',
left:'62%',
top:'6%'
},
{
text:'所选时间段请假',
top:'6%',
left:'83%'
}
],
tooltip: {
trigger: 'axis', //触发类型。[ default: 'item' ] :数据项图形触发,主要在散点图,饼图等无类目轴的图表中使用;'axis'坐标轴触发,主要在柱状图,折线图等会使用类目轴的图表中使用
axisPointer: {
lineStyle: {
color: '#57617B'
}
}
},
/* legend: {
icon: 'rect', //设置图例的图形形状,circle为圆,rect为矩形
itemWidth: 14, //图例标记的图形宽度[ default: 25 ]
itemHeight: 5, //图例标记的图形高度。[ default: 14 ]
itemGap: 13, //图例每项之间的间隔。横向布局时为水平间隔,纵向布局时为纵向间隔。[ default: 10 ]
data: ['移动', '电信', '联通'],
right: '4%', //图例组件离容器右侧的距离
textStyle: {
fontSize: 12,
color: '#F1F1F3'
}
},*/
grid: {
width:'50%',
left: '1%', //grid 组件离容器左侧的距离。
bottom: '14%', //grid 组件离容器下侧的距离。
top:'6%',
containLabel: true //grid 区域是否包含坐标轴的刻度标签[ default: false ]
},
xAxis: [{
type: 'category',
top:10,
boundaryGap: false, //坐标轴两边留白策略,类目轴和非类目轴的设置和表现不一样
axisLine: {
lineStyle: {
color: '#57617B' //坐标轴线线的颜色。
}
},
data: data0.categoryData
}],
yAxis: [{
type: 'value', //坐标轴类型。'value' 数值轴,适用于连续数据;'category' 类目轴,适用于离散的类目数据,为该类型时必须通过 data 设置类目数据;'time' 时间轴;'log' 对数轴.
axisTick: {
show: true //是否显示坐标轴刻度
},
axisLine: {
lineStyle: {
color: '#57617B' //坐标轴线线的颜色
}
},
axisLabel: {
margin: 10, //刻度标签与轴线之间的距离
textStyle: {
fontSize: 14 //文字的字体大小
}
},
splitLine: {
lineStyle: {
color: '#f0f0f0' //分隔线颜色设置
}
}
}],
dataZoom: [
{
type: 'inside',
start: 20,
end: 100
},
{
show: true,
type: 'slider',
y: '90%',
start: 20,
end: 100
}/*,
{
show: false,
xAxisIndex: [0, 1],
type: 'slider',
start: 20,
end: 100
}*/
],
graphic: {
elements: [{
type: 'text',
style: {
text: 90,
fontSize:16,
color:'#000'
},
left: '64.3%',
top: '58%'
},
{
type: 'text',
style: {
text: 115,
fontSize:16,
color:'#000'
},
left: '87%',
top: '58%'
}
]
},
series: [{
name: '年假', //系列名称,用于tooltip的显示,legend 的图例筛选,在 setOption 更新数据和配置项时用于指定对应的系列
type: 'line',
smooth: true, //是否平滑曲线显示
symbol: 'circle', //标记的图形。ECharts 提供的标记类型包括 'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow'
symbolSize: 5, //标记的大小,可以设置成诸如 10 这样单一的数字,也可以用数组分开表示宽和高,例如 [20, 10] 表示标记宽为20,高为10[ default: 4 ]
showSymbol: false, //是否显示 symbol, 如果 false 则只有在 tooltip hover 的时候显示
lineStyle: { //线条样式
normal: {
width: 1 //线宽。[ default: 2 ]
}
},
areaStyle: { //区域填充样式
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ //填充的颜色。
offset: 0.2, // 0% 处的颜色
color: 'rgba(148, 109, 231, 0.8)'
}, {
offset: 0.8, // 80% 处的颜色
color: 'rgba(148, 109, 231, 0.5)'
}], false),
shadowColor: 'rgba(0, 0, 0, 0.1)', //阴影颜色。支持的格式同color
shadowBlur: 10 //图形阴影的模糊大小。该属性配合 shadowColor,shadowOffsetX, shadowOffsetY 一起设置图形的阴影效果
}
},
itemStyle: { //折线拐点标志的样式
normal: {
color: 'rgb(148, 109, 231)',
borderColor: 'rgba(148, 109, 231,0.27)', //图形的描边颜色。支持的格式同 color
borderWidth: 12 //描边线宽。为 0 时无描边。[ default: 0 ]
}
},
data: data0.values
}, {
name: '事假',
type: 'line',
smooth: true,
symbol: 'circle',
symbolSize: 5,
showSymbol: false,
lineStyle: {
normal: {
width: 1
}
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0.2,
color: 'rgba(64, 211, 243, 0.8)'
}, {
offset: 0.8,
color: 'rgba(64, 211, 243, 0.5)'
}], false),
shadowColor: 'rgba(0, 0, 0, 0.1)',
shadowBlur: 10
}
},
itemStyle: {
normal: {
color: 'rgb(64, 211, 243)',
borderColor: 'rgba(64, 211, 243,0.2)',
borderWidth: 12
}
},
data: data0.values2
}, {
name: '病假',
type: 'line',
smooth: true,
symbol: 'circle',
symbolSize: 5,
showSymbol: false,
lineStyle: {
normal: {
width: 1
}
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0.2,
color: 'rgba(251, 172, 72, 0.8)'
}, {
offset: 0.8,
color: 'rgba(251, 172, 72, 0.5)'
}], false),
shadowColor: 'rgba(0, 0, 0, 0.1)',
shadowBlur: 10
}
},
itemStyle: {
normal: {
color: 'rgb(251, 172, 72)',
borderColor: 'rgba(251, 172, 72,0.2)',
borderWidth: 12
}
},
data: data0.values3
},
{
type: 'pie',
radius: [20, '20%'],
center: ['65%', '60%'],
roseType: 'radius',
color: ['#fa6c70', '#946de7', '#41d3f3', '#fbac48'],
data: [{
value: 7,
name: '其他'
}, {
value: 4,
name: '年假'
}, {
value: 6,
name: '事假'
}, {
value: 2,
name: '病假'
}],
label: {
normal: {
textStyle: {
fontSize: 14
},
formatter: function(param) {
return param.name + ':\n' + Math.round(param.percent) + '%';
}
}
},
labelLine: {
normal: {
smooth: true,
lineStyle: {
width: 2
}
}
},
itemStyle: {
normal: {
shadowBlur: 1,
shadowColor: 'rgba(0, 0, 0, 0.4)'
}
},
animationType: 'scale',
animationEasing: 'elasticOut',
animationDelay: function(idx) {
return Math.random() * 200;
}
},{
type: 'pie',
radius: [20, '20%'],
center: ['88%', '60%'],
roseType: 'radius',
color: ['#fa6c70', '#946de7', '#41d3f3', '#fbac48'],
data: [{
value: 7,
name: '其他'
}, {
value: data0.values,
name: '年假'
}, {
value: data0.values2,
name: '事假'
}, {
value: data0.values3,
name: '病假'
}],
label: {
normal: {
textStyle: {
fontSize: 14
},
formatter: function(param) {
return param.name + ':\n' + Math.round(param.percent) + '%';
}
}
},
labelLine: {
normal: {
smooth: true,
lineStyle: {
width: 2
}
}
},
itemStyle: {
normal: {
shadowBlur: 1,
shadowColor: 'rgba(0, 0, 0, 0.4)'
}
},
animationType: 'scale',
animationEasing: 'elasticOut',
animationDelay: function(idx) {
return Math.random() * 200;
}
}
]
}
};