Reputation: 620
I have up to 12 visible linecharts at the same time. Everyone is showing 1 analog or digital signal in realtime. Now I want to scale X-resolution with a pinch, (this is already working on a single line chart) but now all linecharts should zoom at the same time an the same scale factor.
I tried it with a onTouchListener on each linechart, if anyone is touched and scaled, it is tellig it´s scale to the other one.
LineChartObject ob = mLineChartObj.get(lineChartObj);
if (ob.lineChart == null)
// new LineChart
ob.lineChart = new LineChart(mContext);
ob.lineChart.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
float[] val = {ob.lineChart.getScaleX(), ob.lineChart.getScaleY(), ob.lineChart.getX(), ob.lineChart.getY()};
for(int i=0; i<mLineChartObj.size(); i++){
if(i == lineChartObj)
continue;
mLineChartObj.get(i).lineChart.setScaleX(val[0]); //zoom(val[0], val[1], val[2], val[3]);
}
return false;
}
});
I take the scaleX of the actual touched linechart, and give it to the other one, but this doesn't work.
Maybe you know how to solve this issue.
EDIT 1: ######################################################
I tried this code...I have observed the printLines and noticed that the scaleX gets bigger the more I zoom in with touch gestures. As would be expected scaleX gets smaller the more I zoom out with gestures. As well in Y direction, the scaleY gets bigger or smaller.
BUT !! The linechart I call zoom(val[0], val[1 ],....) is only zooming in, although the scaleX/scaleY gets smaller !!
ob.lineChart.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
float[] val = {ob.lineChart.getScaleX(), ob.lineChart.getScaleY(), ob.lineChart.getWidth() / 2, ob.lineChart.getHeight() / 2};
for (int i = 0; i < mLineChartObj.size(); i++) {
if (i == lineChartObj)
continue;
mLineChartObj.get(i).zoomCounter++;
// zoomCounter to get a slower zoom
if (mLineChartObj.get(i).zoomCounter % 10 == 0) {
System.out.println("§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§");
System.out.println("scaleX: " + val[0]);
System.out.println("scaleY: " + val[1]);
System.out.println("Width/2: " + val[2]);
System.out.println("Height/2: " + val[3]);
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
mLineChartObj.get(i).lineChart.zoom(val[0], val[1], mLineChartObj.get(i).lineChart.getWidth() / 2, mLineChartObj.get(i).lineChart.getHeight() / 2); //zoom(val[0], val[1], val[2], val[3]);
System.out.println(val[0] + " " + val[1] + " " + val[2] + " " + val[3]);
System.out.println(val[0] + " " + val[1] + " " + mLineChartObj.get(i).lineChart.getWidth() / 2 + " " + mLineChartObj.get(i).lineChart.getHeight() / 2);
}
}
return false;
}
});
Upvotes: 1
Views: 2890
Reputation: 51421
I suggest you read the tutorial on interaction with the charts. The library provides a listener concept (OnChartGestureListener
) that allows to react on gestures such as panning or zooming that are performed on the chart.
So what you could do is set a listener to the chart that is zoomed, and then in the callback methods from the listener zoom the other charts as well.
Upvotes: 0