【问题标题】:Only trigger pan-end event with amCharts仅使用 amCharts 触发 pan-end 事件
【发布时间】:2016-07-28 11:21:20
【问题描述】:

我正在使用 amCharts 并构建一个 amSerialChart。这里我想触发'pan'事件。但是我只想触发最终事件,这意味着当平底锅结束时。据我可以阅读手册(https://docs.amcharts.com/3/javascriptcharts/ChartCursor),没有明确的事件。但是,也许有人知道如何构建此事件或仅获取最后一个“平移”事件?

【问题讨论】:

    标签: javascript amcharts panning


    【解决方案1】:

    没有专门的活动。但是,您可以通过使用 JavaScript 通用 mouseup/touchend 事件来实现该功能,以捕捉平移结束的时间。即:

      "listeners": [{
        /**
         * rendered event
         * we'll use it to set up custom mouse events as well as
         * pre-zoom the chart
         */
        "event": "rendered",
        "method": function(e) {
    
          // add mouseup events
          e.chart.chartDiv.addEventListener("mouseup", handleEnd);
          e.chart.chartDiv.addEventListener("touchend", handleEnd);
    
          // function that handles pan end (mouse button released or touch ends)
          function handleEnd() {
    
            // check if there was an previous zoom event
            if (e.chart.lastZoomedEvent === undefined)
              return;
    
            // do what we need to do with it
            // ...
            console.log(e.chart.lastZoomedEvent);
    
            // reset 
            e.chart.lastZoomedEvent = undefined;
          }
    
          // pre-zoom the chart
          e.chart.zoomToIndexes(
            e.chart.dataProvider.length - 40,
            e.chart.dataProvider.length - 1);
        }
      }, {
        /**
         * zoomed event
         * we'll use it to track pan/zoom
         */
        "event": "zoomed",
        "method": function(e) {
          // log last zoomed event
          e.chart.lastZoomedEvent = e;
        }
      }]
    

    这是working demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-25
      • 1970-01-01
      • 2023-03-21
      • 2020-12-11
      相关资源
      最近更新 更多