Im working on a Processing App wich is supposed to grap data from a serial port and put in into various graphs. I've downloaded the giCentre Utilities libary to draw the graphs.
Based of one of the examples i got it to plot a simple graph, but since it will be grabbing data from the serial port in real-time i need to be able to add data. Im trying to use the Append() function, but without any luck.
import org.gicentre.utils.stat.*; // For chart classes.
float[] test = {1900, 1910, 1920, 1930, 1940, 1950, 1960, 1970, 1980, 1990};
float[] test2 ={ 19000, 6489, 6401, 7657, 9649, 9767, 12167, 15154, 18200, 23124};
XYChart lineChart;
/** Initialises the sketch, loads data into the chart and customises its appearance.
*/
void setup()
{
size(500,200);
smooth();
noLoop();
PFont font = createFont("Helvetica",11);
textFont(font,10);
// Both x and y data set here.
lineChart = new XYChart(this);
append(test, 2050);
append(test2, 21000);
lineChart.setData(test, test2);
// 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);
}
Isn't the line
append(test, 2050);
append(test2, 21000);
supposed to add a new datapoint at (2050, 21000) ? It would be nice to only have to call these every time serial data comes in and then redraw the plot.
Any help or advice is much appreciated.