ExtJs 图表,如何从"时间"类型轴上的选择掩码获取边界日期



我有带时间序列的ExtJs 4面积图。我希望用户能够水平选择图表的一部分,然后从服务器上获得更高密度的数据。问题是我无法从选择中获取边界日期。我有:

var chart = Ext.create('Ext.chart.Chart', {
  store: store,
  enableMask: true,
  mask: 'horizontal',
  listeners: {
    select: {
        fn: function(me, selection) {
            console.log(arguments); // selection = Object { height: 218, width: 117, x: 665, y: 123 }
        }
    },
  ...

但select监听器只提供像素数据。是否有某种方法可以获得边界轴数据(例如{from:2013-08-01,to:2013-08-20}或某种方法将像素取消投影到值?我很失望,我会说这是一件很基本的事情,但在任何地方都找不到解决方案。提前感谢。

嗯。。它可能不存在这样的方法。在深入研究源代码后,我利用chart.setZoom()方法中的行创建了一个函数,用于手动取消投影X轴数据的掩码选择:

var unprojectXAxis = function(chart, selection) {
  zoomArea = {
    x : selection.x - chart.el.getX(),
    width : selection.width
  };
  xScale = chart.chartBBox.width,
  zoomer = {
      x : zoomArea.x / xScale,
      width : zoomArea.width / xScale
  }
  ends = chart.axes.items[0].calcEnds();
  from = (ends.to - ends.from) * zoomer.x + ends.from;
  to = (ends.to - ends.from) * zoomer.width + from;
  return { from: new Date(from), to: new Date(to) };
}

最新更新