본문 바로가기

[공부용]참고 사이트 모음/[chart]

구글 차트 drag to zoom 이벤트 인지

google charts event for when user zooms or right clicks to reset

 

google charts event for when user zooms or right clicks to reset

I have a google chart. I have enabled the user to drag and zoom by using the option below. var options = { explorer: { keepInBounds: true, actions: ['dragToZoom...

stackoverflow.com

 

google.charts.load('current', {
  packages: ['corechart']
}).then(function () {
  var data = google.visualization.arrayToDataTable([
    [0, 6],
    [1, 7],
    [2, 8],
    [3, 9],
    [4, 5]
  ], true);

  var options = {
    pointSize: 4,
    explorer: {
      keepInBounds: true,
      actions: ['dragToZoom', 'rightClickToReset']
    }
  };

  var container = document.getElementById('chart_div');
  var chart = new google.visualization.LineChart(container);

  google.visualization.events.addListener(chart, 'ready', function () {
    var zoomLast = getCoords();
    var observer = new MutationObserver(function () {
      var zoomCurrent = getCoords();
      if (JSON.stringify(zoomLast) !== JSON.stringify(zoomCurrent)) {
        zoomLast = getCoords();
        console.log('zoom event');
      }
    });
    observer.observe(container, {
      childList: true,
      subtree: true
    });
  });

  function getCoords() {
    var chartLayout = chart.getChartLayoutInterface();
    var chartBounds = chartLayout.getChartAreaBoundingBox();

    return {
      x: {
        min: chartLayout.getHAxisValue(chartBounds.left),
        max: chartLayout.getHAxisValue(chartBounds.width + chartBounds.left)
      },
      y: {
        min: chartLayout.getVAxisValue(chartBounds.top),
        max: chartLayout.getVAxisValue(chartBounds.height + chartBounds.top)
      }
    };
  }

  chart.draw(data, options);
});

 

<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

Detect zoom event for a Google Line chart?

 

Detect zoom event for a Google Line chart?

Is it possible to detect a zoom/rangechange event with Google Line Chart api? If I use a annotated timeline i can do it, but not with a LineChart. As you see i´m trying to synchronise two graphs....

stackoverflow.com

developers.google.com/chart/interactive/docs/events

구글 차트 이벤트관련 공식 레퍼런스

 

Handling Events  |  Charts  |  Google Developers

This page describes how to listen for and handle events fired by a chart. Contents Overview Google charts can fire events that you can listen for. Events can be triggered by user actions, such as when a user clicks on a chart. You can register a Javascript

developers.google.com