October 2017
Intermediate to advanced
294 pages
6h 49m
English
We could actually pre-calculate these operations we're doing on the onDraw() method as there is no need to do it every single time we're drawing the chart on the screen. We could just do it at the setDataPoints(), which is the only point in our custom view that our data set can be changed or replaced:
public void setDataPoints(float[] originalData) { dataPoints = new float[originalData.length]; float minValue = Float.MAX_VALUE; float maxValue = Float.MIN_VALUE; for (int i = 0; i < dataPoints.length; i++) { dataPoints[i] = originalData[i]; if (dataPoints[i] < minValue) minValue = dataPoints[i]; if (dataPoints[i] > maxValue) maxValue = dataPoints[i]; } float verticalDelta = maxValue - minValue; for ...Read now
Unlock full access