Mouse over on bar chart
in
Programming Questions
•
1 year ago
Hello.
I need help doing a bar chart from a array of four numbers.
This is a simple example of a similar sketch i'm doing with a bar chart that reads the data from a cvs.
1. I want to do a mouse over each chart and the color changes individually;
1.1. Theres an if/else on the code, but i think i must create a for loop to do the over on each bar.
2. The next phase is when i click on each bar they fix on a color.
What i need to do to make topic 1 and 2.
Thanks
––––
float [] dados = {
100, 200, 150, 50
};
boolean barrasOver = false;
boolean locked = false;
color f=0;
//float x = 20;
float w = 50;
float espBarras = 10;
float yBarras = 0;
float xBarras;
void setup () {
size (600, 400);
background(255);
smooth();
}
void draw() {
barras (xBarras, w);
}
void barras (float xBarras, float w) {
for (int j=0; j < dados.length; j++) {
xBarras = xBarras + w + espBarras;
noStroke();
yBarras = 300 - dados[j];
fill(f);
rect(xBarras, yBarras, w, dados[j]);
overBarras();
}
}
void overBarras () {
if (mouseX > xBarras && mouseX < xBarras+w+espBarras) {
barrasOver = true;
if (!locked) {
f=200;
}
}
else {
f=0;
barrasOver = false;
}
}
1