void prepareData(boolean averageY) {
		int numPoints = Math.min(MAX_DATA_POINTS, plotMaxData);
		if( x.length > numPoints ) subsample(numPoints, averageY);

		// Find min & max values 
		minX = Integer.MAX_VALUE;
		maxX = Integer.MIN_VALUE;
		minY = Integer.MAX_VALUE;
		maxY = Integer.MIN_VALUE;
		for( int i = 0; (i < x.length) && (i < plotMaxData); i++ ) {
			int xx = x[i];
			minX = Math.min(minX, xx);
			maxX = Math.max(maxX, xx);

			int yy = y[i];
			minY = Math.min(minY, yy);
			maxY = Math.max(maxY, yy);
		}

		if( minY == maxY ) minY = 0; // Otherwise the plot does not show anything when the variance is zero

		// Iterate over all sorted keys
		dataList = new ArrayList<Integer>();
		labelList = new ArrayList<String>();
		int labelEvery = Math.max(Math.min(x.length, plotMaxData) / numberLabelsXaxis, 10);
		for( int i = 0; (i < x.length) && (i < plotMaxData); i++ ) {
			int xx = x[i];

			// Make sure the last point has a coordinate
			if( (i % labelEvery == 0) || (i == (x.length - 1)) || (i == (plotMaxData - 1)) ) labelList.add(Integer.toString(xx));
			else labelList.add("");

			int yy = y[i];
			int scaledCount = (int) ((100.0 * (yy - minY)) / (maxY - minY)); // 'Count' scaled form 0 to 100
			dataList.add(scaledCount);
		}
	}