Need help loading array for XY chart
in
Contributed Library Questions
•
1 year ago
So I need some help loading data into array for use with
giCentreUtils XY Chart. I keep getting "ArrayIndexOutOfBoundsException: 3. Its shown below, I highlighted the line I get the error on. The file I am trying to read in is here:
Ferm.txt.
Any help is greatly appreciated.
Any help is greatly appreciated.
- import org.gicentre.utils.stat.*; // For chart classes.
// Sketch to demonstrate the use of the XYChart class to draw simple line charts.
// Version 1.0, 27th May, 2010.
// Author Jo Wood.
XYChart lineChart;
/** Initialises the sketch, loads data into the chart and customises its appearance.
*/
String[] lines;
float x = 0;
float y = 0;
int count = 0;
import processing.serial.*;
Serial myPort;
BufferedReader reader;
void setup()
{
lines = loadStrings("Ferm.txt");
size(800,700);
smooth();
noLoop();
PFont font = createFont("Helvetica",11);
textFont(font,10);
float [] Xdata = new float [lines.length];
float [] Ydata = new float [lines.length];
for (int i = 1; i < lines.length; i++) {
String[] pieces = split(lines[i], ",");
x = float(pieces[3]);
y = float(pieces[6]);
Ydata[i] = y;
Xdata[i] = x;
}
// Both x and y data set here.
lineChart = new XYChart(this);
lineChart.setData(Xdata, Ydata);
// Axis formatting and labels.
lineChart.showXAxis(true);
lineChart.showYAxis(true);
lineChart.setMinY(0);
lineChart.setYFormat("00.00"); // Monetary value in $US
lineChart.setXFormat("00.00"); // Year
// Symbol colours
lineChart.setPointColour(color(180,50,50,100));
lineChart.setPointSize(5);
lineChart.setLineWidth(2);
}
/** Draws the chart and a title.
*/
void draw()
{
background(255);
textSize(9);
lineChart.draw(15,15,width-30,height-30);
// Draw a title over the top of the chart.
fill(120);
textSize(20);
text("Fermentation Temp", 70,30);
textSize(11);
//text("Gross domestic product measured in inflation-corrected $US", 70,45);
}
1