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
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}