datazoom的start,end只能设置百分比吗,有没办法设置绝对值?
问题简述 (One-line summary)
X轴为时间,Y轴为数字,1分钟会动态增加1条数据,想通过datazoom显示最新一个小时的数据. 因为数据量在不停的增加,不好设置百分比,有没有办法或其他参考方案设置datazoom的start,end为最新一个小时.
类似于highstock的
rangeSelector : {
buttons : [{
type : 'hour',
count : 1,
text : '1H'
},{
type : 'hour',
count : 2,
text : '2H'
},{
type : 'hour',
count : 3,
text : '3H'
}, {
type : 'day',
count : 1,
text : '1D'
}, {
type : 'all',
count : 1,
text : 'All'
}],
selected: 0,
inputEnabled : false
}
版本及环境 (Version & Environment)
- ECharts 版本 (ECharts version):3.1.10
- 浏览器类型和版本 (Browser version):IE11
- 操作系统类型和版本 (OS Version):windows 7
重现步骤 (Steps to reproduce)
期望结果 (Expected behaviour)
可能哪里有问题 (What went wrong)
ECharts配置项 (ECharts option)
option = {
title: {
text: '温度(°C)',
x: 'center'
},
legend: {
show: true,
right: '0',
data: [
'現像1温度','現像2温度','現像3温度'
]
},
tooltip: {
trigger: 'axis',
formatter: function(params) {
var result = "";
for (var i = 0; i < params.length; i++) {
var p = params[i];
var seriesName = p.seriesName;
if (typeof(p.value) == "undefined") {
result += seriesName + ', <br />';
} else {
var date = new Date(p.value[0]);
var value = p.value;
result += seriesName.substring(0,seriesName.length - 2) + ', ' + date.toLocaleString() + ' ,' + p.value[1] + '<br />';
}
}
return result;
}
},
xAxis: [{
type: 'time'
}],
yAxis: [{
type: 'value',
axisLabel: {
formatter: '{value} °C'
}
}],
grid: {
left: '6%',
right: '9%',
bottom: '9%',
containLabel: true
},
dataZoom: [{
type: 'inside',
orient: 'horizontal'
},{
type: 'slider',
orient: 'horizontal'
},{
type: 'inside',
orient: 'vertical'
},{
type: 'slider',
orient: 'vertical'
}],
series: [
{
name: '現像1温度',
type: 'line',
showSymbol: false,
hoverAnimation: false,
sampling: 'max',
markLine: {
symbol: ['none', 'none'],
data: [{
name: '上限',
type: 'max',
yAxis: 31.0,
lineStyle: {
normal: {
color: '#FF3030'
}
},
label: {
normal: {
formatter: '{c}{b}'
}
}
}, {
name: '下限',
type: 'min',
yAxis: 29.0,
lineStyle: {
normal: {
color: '#FF3030'
}
},
label: {
normal: {
formatter: '{c}{b}'
}
}
}]
},
data: [
['2016/05/30 00:00:00', 31.0],
['2016/05/30 00:01:00', 31.0],
['2016/05/30 00:27:00', 30.6],
['2016/05/30 00:28:00', 30.5],
['2016/05/30 00:29:00', 30.5],
['2016/05/30 00:30:00', 30.5],
['2016/05/30 00:31:01', 30.5],
['2016/05/30 00:32:00', 30.6],
['2016/05/30 00:33:00', 30.6],
['2016/05/30 00:34:00', 30.6]
]
},
{
name: '現像2温度',
type: 'line',
showSymbol: false,
hoverAnimation: false,
sampling: 'max',
markLine: {
symbol: ['none', 'none'],
data: [{
name: '上限',
type: 'max',
yAxis: 31.0,
lineStyle: {
normal: {
color: '#FF3030'
}
},
label: {
normal: {
formatter: '{c}{b}'
}
}
}, {
name: '下限',
type: 'min',
yAxis: 29.0,
lineStyle: {
normal: {
color: '#FF3030'
}
},
label: {
normal: {
formatter: '{c}{b}'
}
}
}]
},
data: [
['2016/05/30 00:00:00', 30.6],
['2016/05/30 00:01:00', 30.7],
['2016/05/30 00:27:00', 30.7],
['2016/05/30 00:28:00', 30.6],
['2016/05/30 00:29:00', 30.7],
['2016/05/30 00:30:00', 30.7],
['2016/05/30 00:31:01', 30.7],
['2016/05/30 00:32:00', 30.8],
['2016/05/30 00:33:00', 30.8],
['2016/05/30 00:34:00', 30.9]
]
},
{
name: '現像3温度',
type: 'line',
showSymbol: false,
hoverAnimation: false,
sampling: 'max',
markLine: {
symbol: ['none', 'none'],
data: [{
name: '上限',
type: 'max',
yAxis: 31.0,
lineStyle: {
normal: {
color: '#FF3030'
}
},
label: {
normal: {
formatter: '{c}{b}'
}
}
}, {
name: '下限',
type: 'min',
yAxis: 29.0,
lineStyle: {
normal: {
color: '#FF3030'
}
},
label: {
normal: {
formatter: '{c}{b}'
}
}
}]
},
data: [
['2016/05/30 00:00:00', 30.8],
['2016/05/30 00:01:00', 30.8],
['2016/05/30 00:27:00', 30.9],
['2016/05/30 00:28:00', 30.9],
['2016/05/30 00:29:00', 30.9],
['2016/05/30 00:30:00', 31.0],
['2016/05/30 00:31:01', 30.7],
['2016/05/30 00:32:00', 30.8],
['2016/05/30 00:33:00', 30.8],
['2016/05/30 00:34:00', 30.9]
]}
]};
其他信息 (Other comments)
highstock参考示例: http://jsfiddle.net/jugal/GX749/
可以设置绝对的数值,http://echarts.baidu.com/option.html#dataZoom-slider.startValue
谢谢!绝对值的问题搞定了. 但有一个新的问题,想达到以下效果. 当用户手动移动过导航块时,即使数据有更新,也不想重新移动到之前程序设置的位置(目前每次更新数据时都会重新移动) 但如果用户没有移动过导航快时,想一直显示最新1个小时的数据(看起来就是图表不停地往左移动) 为了达到这种效果,需要知道当前的实际的startvalue,endvalue是什么, 但用option.dataZoom.start取得的值还是原始的值. 有什么好的建议吗?
@happyzhangwen @pissang 我也想设置绝对值,设置 startValue 后还是无效(没有设置start)。 能给出你的例子,如何设置绝对值的? 谢谢。
This issue is closed due to not being active. Please feel free to open it again (for the author) or create a new one and reference this (for others) if you have further questions.