I’m having a bit of confusion on understanding just simple placement of my data. I’m making a pie chart based off of a data set so I know I have to plug them into where it says diameter and such but can someone help clarify this a bit more for me.
void pieChart(float diameter, int[] data) {
float lastAngle = 0;
for (int i = 0; i < data.length; i++) {
float gray = map(i, 0, data.length, 0, 255);
fill(gray);
arc(width/2, height/2, diameter, diameter, lastAngle, lastAngle+radians(data[i]));
lastAngle += radians(data[i]);
I have all my data values ready to plug in I just need clarification as to where they go and why!
Here is my full code:
Boolean barGraphButton = true;
int beaver = 0;
// create array for data
int[] day;
int[] time;
float [] temp;
int leftMargin = 100;
int rightMargin = 50;
int topMargin = 20;
int bottomMargin = 80;
int barWidth;
void setup() {
size(1200, 700);
smooth();
frame.setResizable(true);
// load data from csv file
String[] lines = loadStrings("data.csv");
//use number of columns to set length
day = new int[lines.length];
time = new int[lines.length];
temp = new float[lines.length];
for (int i=0; i<lines.length; i++) {
//split into 2 strings
String[] tokens = splitTokens(lines[i], ",");
// put 2nd string into int array
day[i] = int(tokens[1]);
time[i] = int(tokens[2]);
temp[i] = float(tokens[3]);
}
//set bar width according to # of rows of data
barWidth = (width -leftMargin-rightMargin)/ lines.length;
println(barWidth);
}
void barGraph() {
fill(26, 129, 13);
//set height of bars
for (int i=0; i<day.length; i++) {
float h = day[i];
rect((i*barWidth)+leftMargin, height - (h+bottomMargin), barWidth*.85, h);
}
// Title Text
textSize(24);
textAlign(CENTER);
fill(0);
text("Beaver Body Temperature", width/2, height/6);
}
void pieChart(){
}
void draw() {
background(255);
switch(beaver) {
case 0:
barGraph();
break;
case 1:
pieChart();
break;
case 2:
break;
}
//create Toggle Button to display bar or line graph
color C1 = color(#E3DC10);
color C2 = color(#550183);
if (barGraphButton) {
fill(C1);
rect(width*.8, height/25, 100, 25);
//text during bar graph view
textSize(10);
fill(0);
text("switch view", width*.8+50, height/25+13);
} else {
fill(C2);
rect(width*.8, height/25, 100, 25);
textSize(10);
text("switch view", width*.8+50, height/25+13);
}
}
void mouseClicked() {
// click from Bar graph to Line graph
beaver = (beaver+1)%2;
beaver = (beaver+1)%3;
//if (barGraphButton) {
// if (mouseX > width*.8 && mouseX < (width*.8)+100 && mouseY > height/25 && mouseY < height/25+25) {
// barGraphButton = false;
// }
//} else {
// // Click from Line graph to Bar graph
// if (mouseX > width*.8 && mouseX < (width*.8)+100 && mouseY > height/25 && mouseY < height/25+25) {
// barGraphButton = true;
// }
//}
}
sadly I don’t think i can provide my data file to run the code.