private double[] getNormalisedData(int width, int height) {
        
        int averageSize = Math.max(data.length / width, 1);
        double[] result = new double[data.length / averageSize];
        
        currentMaxValue = Double.NEGATIVE_INFINITY;
        
        // Average the data such that it fits on the x axis.
        for (int i = 0; i < result.length; i++) {
        
            double sum = 0;
            for (int j = 0; j < averageSize; j++) {
                
                double current = data[i * averageSize + j];
                sum += current;
            }
            
            result[i] = sum / averageSize;
            currentMaxValue = Math.max(result[i], currentMaxValue);
        }
        
        // Scale the data to fit the y axis.
        for (int i = 0; i < result.length; i++) {
            
            result[i] = result[i] * height / currentMaxValue;
        }
        
        return result;
    }