同步两个 mpandroid 图表图形拖动和缩放
Sync the two mpandroidcharts graphs dragging and zomming
我正在使用 MPAndroidChart,我有一个要求,我必须同步两个图表的拖动和缩放,比如如果我缩小、放大或拖动一个图表中的任何一个,那么其他图表应该在 X 轴上缩小、放大或拖动到相同程度。
示例:如果我将上图拖动到 X 轴上的第 12 个点,则下图也应自动拖动到 X 轴上的第 12 个点。
伙计们,我需要知道如何做到这一点,我对 mpchartandroid 库足够熟悉。
使用 OnChartGestureListener
.
https://github.com/PhilJay/MPAndroidChart/wiki/Interaction-with-the-Chart
我写了一个函数来做这个,我调用这个函数的拖动和缩放监听器。工作完美。
private void syncCharts(Chart mainChart, LineChart[] otherCharts) {
Matrix mainMatrix;
float[] mainVals = new float[9];
Matrix otherMatrix;
float[] otherVals = new float[9];
mainMatrix = mainChart.getViewPortHandler().getMatrixTouch();
mainMatrix.getValues(mainVals);
for (LineChart tempChart : otherCharts) {
otherMatrix = tempChart.getViewPortHandler().getMatrixTouch();
otherMatrix.getValues(otherVals);
otherVals[Matrix.MSCALE_X] = mainVals[Matrix.MSCALE_X];
otherVals[Matrix.MTRANS_X] = mainVals[Matrix.MTRANS_X];
otherVals[Matrix.MSKEW_X] = mainVals[Matrix.MSKEW_X];
otherMatrix.setValues(otherVals);
tempChart.getViewPortHandler().refresh(otherMatrix, tempChart, true);
}
}
我正在使用 MPAndroidChart,我有一个要求,我必须同步两个图表的拖动和缩放,比如如果我缩小、放大或拖动一个图表中的任何一个,那么其他图表应该在 X 轴上缩小、放大或拖动到相同程度。 示例:如果我将上图拖动到 X 轴上的第 12 个点,则下图也应自动拖动到 X 轴上的第 12 个点。
伙计们,我需要知道如何做到这一点,我对 mpchartandroid 库足够熟悉。
使用 OnChartGestureListener
.
https://github.com/PhilJay/MPAndroidChart/wiki/Interaction-with-the-Chart
我写了一个函数来做这个,我调用这个函数的拖动和缩放监听器。工作完美。
private void syncCharts(Chart mainChart, LineChart[] otherCharts) {
Matrix mainMatrix;
float[] mainVals = new float[9];
Matrix otherMatrix;
float[] otherVals = new float[9];
mainMatrix = mainChart.getViewPortHandler().getMatrixTouch();
mainMatrix.getValues(mainVals);
for (LineChart tempChart : otherCharts) {
otherMatrix = tempChart.getViewPortHandler().getMatrixTouch();
otherMatrix.getValues(otherVals);
otherVals[Matrix.MSCALE_X] = mainVals[Matrix.MSCALE_X];
otherVals[Matrix.MTRANS_X] = mainVals[Matrix.MTRANS_X];
otherVals[Matrix.MSKEW_X] = mainVals[Matrix.MSKEW_X];
otherMatrix.setValues(otherVals);
tempChart.getViewPortHandler().refresh(otherMatrix, tempChart, true);
}
}