We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm trying to read some values from a csv file using loadString, then parse them to float and display a chart using the giCentre library. However I get the ArrayIndexOutOfBoundException error on the lineChart.draw(..); line and not sure where it comes from. Thanks
Here's my code
import org.gicentre.utils.stat.*;
XYChart lineChart;
String fileName = "32140";
//my 2 arrays used for x and y axis
float[] ms = new float[200];
float[] delta = new float[200];
void setup()
{
size(1500,1000);
String[] lines = loadStrings(fileName + "_clean.csv");
for(int i = 0; i < lines.length; i++){
float[] fullList = parseFloat(split(lines[i], ','));
ms[i] = fullList[1]; //only need values in column 1
delta[i] = fullList[3]; //only need values in column 3
}
textFont(createFont("Arial",10),10);
// Both x and y data set here.
lineChart = new XYChart(this);
lineChart.setData(ms, delta);
// Axis formatting and labels.
lineChart.showXAxis(true);
lineChart.showYAxis(true);
lineChart.setMinY(0);
lineChart.setYFormat("#####");
lineChart.setXFormat("0000");
// 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); //error here
// Draw a title over the top of the chart.
fill(120);
textSize(20);
text("Income per person, United Kingdom", 70,30);
textSize(11);
text("Gross domestic product measured in inflation-corrected $US",
70,45);
}