简体   繁体   English

echarts dataZoom 事件不返回时间戳,只返回百分比

[英]echarts dataZoom event does not return timestamp but only percentages

I got a chart with a dataZoom component.我得到了一个带有 dataZoom 组件的图表。 The x-axis is of type time . x 轴的类型为time Zooming and roaming the chart works perfectly.缩放和漫游图表效果很好。 But when I listen for the dataZoom event to hook into the zooming process I only get percentage values (0-100) from the event as current position.但是,当我侦听dataZoom事件挂钩到缩放过程时,我只能从事件中获取百分比值 (0-100) 作为当前位置。

the dataZoom config:数据缩放配置:

dataZoom: {
   start: 0,
   end: 3,
   showDetail: false
}

my xAxis config:我的 xAxis 配置:

xAxis: {
    type: 'time',
    boundaryGap: false,
    splitLine: {
        show: true,
        lineStyle: {
            color: '#ddd',
            type: 'dashed'
        }
    },
    axisLine: {
        show: false
    }
},

I listen for the event like this:我听这样的事件:

myChart.on('dataZoom', function (evt) {
  console.log('zoom', evt);
})

And I get this console output for evt :我得到了evt控制台输出:

{
  "type": "datazoom",
  "from": "viewComponent_17_0.8229841241707196",
  "dataZoomId": "\u0000\u0000-\u00000",
  "start": 1.6141473287753287,
  "end": 11.178346465795
}

I would expect it to be something like:我希望它是这样的:

"start" : "2012-12-01 15:30:00Z",
"end" : "2012-12-01 15:40:00Z"

is this possible?这可能吗?

Currently you don't get it from the event.目前你没有从事件中得到它。 There is an issue connected to this: 4906有一个与此相关的问题: 4906

A work around is to get the value from getOption like this:解决方法是像这样从 getOption 获取值:

const { startValue, endValue } =  echart.getEchartsInstance().getOption().dataZoom[0]

You can do this in your on dataZoom event handler (instead of using the values in the evt)您可以在 dataZoom 事件处理程序中执行此操作(而不是使用 evt 中的值)

I came across the same problem the following simple code works perfectly for me:我遇到了同样的问题,以下简单的代码非常适合我:

myChart.on('dataZoom', function() {
  var option = myChart.getOption();
  console.log(option.dataZoom[0].startValue, option.dataZoom[0].endValue);
});

please try this请试试这个

myChart.on('datazoom', function (evt) {
  var axis = myChart.getModel().option.xAxis[0];
  var starttime = axis.data[axis.rangeStart];
  var endtime = axis.data[axis.rangeEnd];
  console.log(starttime,endtime);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM