int[] data = {120, 200, 300, 150, 250}; // Data representing the height of each bar String[] labels = {"A", "B", "C", "D", "E"}; // Labels for each bar int numBars = data.length; int barWidth = 50; int maxDataValue; int barSpacing = 20; int xOffset, yOffset; void setup() { size(800, 600); maxDataValue = max(data); xOffset = (width - (barWidth + barSpacing) * numBars) / 2; yOffset = 50; } void draw() { background(255); // Drawing the bars for (int i = 0; i < numBars; i++) { int barHeight = (data[i] * (height - 2 * yOffset)) / maxDataValue; int barX = xOffset + i * (barWidth + barSpacing); int barY = height - yOffset - barHeight; color barColor = getColor(i); // Get color based on index fill(barColor); rect(barX, barY, barWidth, barHeight); // Display frequency on top of each bar fill(0); textAlign(CENTER, CENTER); text(data[i], barX + barWidth / 2, barY - 10); // Display label below each bar fill(0); text(labels[i], barX + barWidth / 2, height - 10); } } // Function to get color based on index color getColor(int index) { switch (index % 3) { case 0: return color(255, 0, 0); // Red case 1: return color(0, 255, 0); // Green case 2: return color(0, 0, 255); // Blue default: return color(0); // Black } }