java - Plotting Multiple Graphs in GRAL -


i'm using library gral graphing out lines , data. reason, i'm having trouble graphing multiple lines on same xy plot. here's code:

import java.awt.color; import javax.swing.jframe; import de.erichseifert.gral.data.datatable; import de.erichseifert.gral.plots.xyplot; import de.erichseifert.gral.plots.lines.defaultlinerenderer2d; import de.erichseifert.gral.plots.lines.linerenderer; import de.erichseifert.gral.plots.points.pointrenderer; import de.erichseifert.gral.ui.interactivepanel;  public class graphtest extends jframe { public graphtest(double x1, double y1) {      //sets defaults jframe     setdefaultcloseoperation(exit_on_close);     setsize(600, 400);      //creates data table , runs loop incrementally plot out points of sine curve on step .25     datatable data = new datatable(double.class, double.class);     (double x = -5.0; x <= 5.0; x+=0.25) {         double y = 5.0*math.sin(x);         data.add(x, y);     }      //plot out data , set xyplot in jframe, connect lines , change colors     xyplot plot = new xyplot(data);     getcontentpane().add(new interactivepanel(plot));     linerenderer lines = new defaultlinerenderer2d();     plot.setlinerenderer(data, lines);     color color = new color(0.0f, 0.3f, 1.0f);     plot.getpointrenderer(data).setcolor(color);     plot.getlinerenderer(data).setcolor(color);      //plot out point (4,5) on same graph sine graph     datatable data2 = new datatable(double.class, double.class);     data2.add(x1, y1);     xyplot plot2 = new xyplot(data2);     //getcontentpane().add(new interactivepanel(plot2));     //plot2.setlinerenderer(data2, lines);     //plot2.getpointrenderer(data2).setcolor(color);     //plot2.getlinerenderer(data2).setcolor(color); }  public static void main(double x1, double y1) {     graphtest frame = new graphtest(x1, y1);     frame.setvisible(true); } } 

the program runs fine way is, un-comment following lines make plot 2 graphs on same plot:

    //getcontentpane().add(new interactivepanel(plot2));     //plot2.setlinerenderer(data2, lines);     //plot2.getpointrenderer(data2).setcolor(color);     //plot2.getlinerenderer(data2).setcolor(color); 

and jframe goes blank , program seems freeze. i'm beginner library gral (i started using today), please excuse lack of expertise. also, fyi, code being run via command in same package class following code:

graphtest.main(4,5); 

the problem not sure how plot 2 graphs (a sine curve , point) on same xy plot. lastly, here image of current code looks when run:

enter image description here

thanks in advance.

this old question, here how solved same problem:

on part create xy plot, add more data sources.

from

xyplot plot = new xyplot(data); 

to

xyplot plot = new xyplot(data, moredata); 

make sure style both data points individually.


Comments

Popular posts from this blog

php - How can I edit my code to echo the data of child's element where my search term was found in, in XMLReader? -

iphone - Using nested NSDictionary with Picker -

javascript - Iterate over array and calculate average values of array-parts -