echarts
echarts copied to clipboard
柱状图添加dataZoom后,dataIndex计算错误
问题简述 (One-line summary)
我在柱状图添加dataZoom,设置start为50,end为100后,发现在给柱子设置颜色时,params.dataIndex获取的索引并不是改柱子在原数据中的索引,而是与start位置相关,导致我无法默认选中最后一根柱子
版本及环境 (Version & Environment)
- ECharts 版本 (ECharts version): echarts-all-2.1.8.js
- 浏览器类型和版本 (Browser version): chrome 48.0.2564.116 m
- 操作系统类型和版本 (OS Version): window8.1中文版
重现步骤 (Steps to reproduce)
- 直接运行option 2.
期望结果 (Expected behaviour)
默认选中最后一根柱子(最后一根柱子颜色加深)
可能哪里有问题 (What went wrong)
或许是我对dataZoom理解的有问题。。
ECharts配置项 (ECharts option)
var dataList = [79.5, 81, 81, 81, "-", 83, 83, 81, 79.5, 81, 84.5, 85, 85, 85, 85, 85, 85, 85, 85, 84.5, 83, 79.5, 79.5, 77.5];
var option = {
tooltip: {
trigger: 'axis',
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
},
showDelay: 0,
formatter: function(params) {
var tar = params[0];
var dataIndex = tar.dataIndex; // 这里的索引计算也有类似问题
return str;
}
},
title: {
text: '质量指标历时趋势',
x: 'center',
textStyle: {
color: '#000',
fontFamily: '微软雅黑',
fontWeight: 'normal',
align: 'left',
baseline: 'bottom'
}
},
calculable: true,
//animation: false,
grid: {
y: 20,
y2: 70,
x: 60,
x2: 50,
borderWidth: 0
},
dataZoom: {
show: true,
realtime: true,
start: 50,
end: 100,
height: 25,
fillerColor: '#0888C3',
handleColor: '#A3E1A3',
dataBackgroundColor: '#CCCCCC'
},
xAxis: [{
type: 'category',
axisTick: {
show: true,
lineStyle: {
color: '#444'
}
},
axisLine: {
show: true,
lineStyle: {
color: '#9FA5AF'
}
},
axisLabel: {
formatter: function(v) {
if (v == '暂无数据') {
return v;
} else {
return v.substr(-2, 2);
}
}
},
splitLine: {
show: false,
lineStyle: {
color: '#483d8b',
type: 'dashed',
width: 1
}
},
splitArea: {
show: false,
areaStyle: {
color: ['rgba(144,238,144,0.3)', 'rgba(135,200,250,0.3)']
}
},
data: ["2016072013", "2016072014", "2016072015", "2016072016", "2016072017", "2016072018", "2016072019", "2016072020", "2016072021", "2016072022", "2016072023", "2016072100", "2016072101", "2016072102", "2016072103", "2016072104", "2016072105", "2016072106", "2016072107", "2016072108", "2016072109", "2016072110", "2016072111", "2016072112"]
}],
yAxis: [{
type: 'value',
scale: true,
min: 20,
max: 100,
axisLabel: {
formatter: '{value}'
},
axisLine: {
show: true,
lineStyle: {
color: '#fff'
}
},
splitLine: {
show: false,
lineStyle: {
color: '#483d8b',
type: 'dashed',
width: 1
}
},
splitArea: {
show: false,
areaStyle: {
color: ['rgba(144,238,144,0.3)', 'rgba(135,200,250,0.3)']
}
},
nameTextStyle: {
color: '#0FF',
fontFamily: '微软雅黑',
fontWeight: 'bold',
align: 'left',
baseline: 'bottom'
}
}],
series: [{
name: '综合质量',
type: 'bar',
barMaxWidth: 40,
padding: 5, // [5, 10, 15, 20]
itemGap: 5,
itemStyle: {
normal: {
color: function(params) {
// 当设置dataZoom,这里dataIndex计算与拖动比例相关
if (params.dataIndex === dataList.length - 1) {
return '#1F4E79';
} else {
return '#0888C3';
}
}
}
},
data: dataList
}]
};
其他信息 (Other comments)
期望的效果应该是这样的

3 里不存在这个问题
恩,试过了,3确实没有这个问题,谢谢!