-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBarChart.pde
More file actions
98 lines (82 loc) · 2.34 KB
/
Copy pathBarChart.pde
File metadata and controls
98 lines (82 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
final float MARGINY = 350; //<>//
final float GAPPERCENT = 30;
class BarChart {
ArrayList<String> names;
ArrayList<Integer> frequency;
float barSize;
float largestFreq;
float multiple;
float gap;
float barSpace;
String xAxis;
String yAxis;
float MARGINX;
BarChart(ArrayList<String> name, ArrayList<Integer> frequency, String yAxis, String xAxis) { //<>//
this.names = name; //<>//
this.frequency = frequency;
this.xAxis = xAxis;
this.yAxis = yAxis;
barSize = ((SCREENX + 2000)/names.size())-((GAPPERCENT*((SCREENX-(MARGINX))/names.size()))/100);
gap = ((GAPPERCENT*((SCREENX-(X))/names.size()))/100);
barSpace = ((SCREENX + 2000)/names.size());
largestFreq=0;
for (Integer freq : frequency) {
if (largestFreq<freq) {
largestFreq=(float)freq;
}
}
multiple = -((float)(SCREENY-200-(MARGINY+30))/largestFreq); //<>//
}
void draw() {
noStroke();
MARGINX = right;
int counter = 0;
for (Integer freq : frequency)
{
fill(255, 0, 120);
rect(MARGINX + (barSpace)*counter, SCREENY-MARGINY, barSize, multiple*freq);
fill(0);
if (barSize/1.5>18) textSize(18);
else textSize(barSize/1.5);
textAlign(CENTER);
text(freq, MARGINX + barSize/2 + (barSpace)*counter, SCREENY-MARGINY+(multiple*freq)-10);
counter++;
}
counter = 0;
for (String name : names) {
fill(0);
if (barSize/2>17) textSize(17);
else textSize(barSize/2);
textAlign(CENTER);
text(name, MARGINX + barSize/2 + barSpace*counter, SCREENY+15-(MARGINY));
counter++;
}
fill(200);
rect(2, 50, 63, 600);
fill(200);
rect(SCREENX-65, 50, 64, 600);
fill(0);
rect(0, 0, 2000, 0);
fill(0);
rect(0, 0, 1, 2000);
fill(0);
rect(SCREENX - 1, 0, 1, 2000);
noStroke();
fill(200);
rect(SCREENX/3, 41, SCREENX/3, 1);
fill(200);
rect(0, 50, 64, 600);
fill(200);
rect(SCREENX-64, 50, 64, 600);
textSize(24);
fill(0);
textAlign(CENTER);
translate(57/1.5, SCREENY/2);
rotate(radians(-90));
text(yAxis, 70, 0);
textSize(24);
textAlign(CENTER);
rotate(radians(90));
text(xAxis, SCREENX/2, SCREENY/2 - 250);
}
}