google / charts

https://pub.dev/packages/charts_flutter
Apache License 2.0
2.8k stars 1.24k forks source link

Chart click listener #400

Open WildOrangutan opened 4 years ago

WildOrangutan commented 4 years ago

Is it possible to have a callback, that's triggered by clicking anywhere on the chart, and also returns click position?

What I want to achieve, is to have a chart, where you could add points, by clicking on the chart.

WildOrangutan commented 4 years ago

My current workaround below, if it happens to help anyone. I created custom ChartBehevior specifically for CartesianChart.

// onAttach()
_chart = chart as CartesianChart;
chart.addGestureListener(listener);
chart.registerTappable(this);

// on callback from gesture listener
var xAxis = _chart.getMeasureAxis(axisId: Axis.primaryMeasureAxisId);
// var yAxis = _chart.domainAxis;
var xScale = xAxis.scale;
var xPx = pointPx.x;
var x = xScale.reverse(xPx);