Hi , I am trying to plot the data with the country that the user has entered.
My data is formatted in the following way.
Country ,1975 ,1976 ....2014 ;
Afghanistan, 23, 24 ....40.
I want to plot the row data with the code below but I am getting Null Pointer Exception. I can't see where I have gone wrong. Can someone please help me ?
import org.gicentre.utils.stat.*;
import org.gicentre.utils.gui.*;
XYChart Chart;
Table Men ;
TextInput textInput;
float[] yearstoplot = new float[40];
void setup()
{
size(1000, 1000);
Table Men = loadTable ("Mendatare.csv","header,csv");
Chart =new XYChart(this);
Chart.setMaxX(2015);
Chart.setMinX(1974);
Chart.setXFormat("####");
Chart.setMaxY(30);
Chart.setMinY(18);
Chart.showXAxis(true);
Chart.showYAxis(true);
Chart.setPointColour(color(180,4, 110));
Chart.setPointSize(5);
Chart.setLineColour(color(180,4, 110));
Chart.setLineWidth(2);
textSize(20);
PFont fonttextbox = createFont("BodoniMT-48",14);
textInput= new TextInput(this,fonttextbox,14);
for (int i=0; i<yearstoplot.length; i++)
{
yearstoplot[i] = (i+1975);
}
println(yearstoplot);
}
void keyPressed ()
{
textInput.keyPressed();
if (keyCode ==ENTER))
{
String countrytoplot = textInput.getText();
TableRow target = Men.findRow(countrytoplot, "Country/Region/World"); // here is the problem
float x0 = target.getFloat(3); //get value from column 3
float x1 = target.getFloat(4);
float x2 = target.getFloat(5);
float x3 = target.getFloat(6);
float x4 = target.getFloat(7);
float x5 = target.getFloat(8);
float x6 = target.getFloat(9);
float x7 = target.getFloat(10);
float x8 = target.getFloat(11);
float x9 = target.getFloat(12); //get value from column 12
float[] datatoplot = {x0,x1,x2,x3,x4,x5,x6,x7,x8,x9}; //aggregate the values
Chart.setData(yearstoplot,datatoplot);
}
}
void draw()
{
background(255);
fill(0);
textAlign(CENTER);
text("Obesity over the years for countries",300, 20);
strokeWeight(2.0);
stroke(40);
fill(0,200);
rect(770,20,215,60,8);
textAlign(RIGHT);
fill(0);
textSize(10);
text("Please type in a country name", width-50,30);
textInput.draw(780,40);
Chart.draw(30,80,width-400,height-300);
}
Is there a better way of doing it ?