Scaling line graphs with high numbers
in
Programming Questions
•
1 year ago
I've got what I think is a scaling issue at hand. I've got some code written for a simple line-graph generator, (code below).
The length of the line is determine by the second value in each line of my input .csv file, (also below).
Seeing as how the line drawn is x pixels long, I'm going to run into a problem once I try to draw lines where the input number is in the thousands or millions.
How would I scale my lines and the size of the sketch window to accommodate for such large values?
Any tips?
The length of the line is determine by the second value in each line of my input .csv file, (also below).
Seeing as how the line drawn is x pixels long, I'm going to run into a problem once I try to draw lines where the input number is in the thousands or millions.
How would I scale my lines and the size of the sketch window to accommodate for such large values?
Any tips?
- // Drawing line graphs of some counts
// Current Goal: scale lines that have values in the millions
// Variables
String[] lines;
int index = 0;
int size_index = 0;
int i = 0;
int liner = 30;
int maxline = 0;
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;
// Setup runs once
void setup() {
frame.setResizable(true);
// Set background color to dark blue
background(43, 58, 66);
// Set line color to orange
stroke(235, 85, 13);
// Load the csv file which contains the counts
lines = loadStrings("rar.csv");
for (i = 0; i < lines.length; i++) {
String[] pieces = split(lines[size_index], ',');
int x = int(pieces[0]);
int y = int(pieces[1]);
if (y > maxline) {
maxline = y;
} else {
maxline = maxline;
}
size_index = size_index + 1;
}
// Multiplying lines.length by 10 because of the iteration on the index spacer later in draw()
size(liner+(maxline + liner),(liner+(lines.length * 10)+liner));
}
// Draw runs continuously
void draw() {
if (index < lines.length) {
// Split the input file by comma
String[] pieces = split(lines[index], ',');
// Variables to set line length and spacing
x1 = 30;
y1 = liner;
x2 = int(pieces[1]);
y2 = liner;
// Increase line thickness to 2
strokeWeight(2);
// Set the cap to the end of lines be square
strokeCap(SQUARE);
// 10 = Starting point of line, line will extend to the right
line(x1,y1,(x2+x1),y2);
// Iterate the line count
index = index + 1;
// Increment the liner value by 10, this is the spacing between lines
liner = liner + 10;
}
} - 1,50
2,60
3,70
4,80
5,90
6,100
7,20
8,90
9,520
10,300
11,50
12,65
13,80
14,90
15,265
16,40
17,90
18,22
19,56
20,301
1