Hi, I am building a program which plots data from an Nx3 array - the first column being X-axis data and the other two being two sets of Y-axis data. The desired output is a JFrame with two curves plotted on a graph - one black and one red. Because the program does not know how large the array is until it is inputted, the plot must be scaled to fit within the JFrame. I am also adding text to the axes, but have not completely implemented this yet.
The problem: I am having trouble getting Graphics2D to display the plots. The way I am making the plots is assigning points from the scaled arrays and utilizing Line2D to connect the points. My Implementation so far - the main class, the class containing paintComponent, and a test suite - are shown below. Please note that the axisScale method and some of the arrays are for text display, and have not yet been implemented in the PlotBuild class.
Any advice about how to proceed from here is greatly appreciated. Thank you in advance!
Hello Nick, and welcome to the Ranch! Have you considered using JFreeChart? or is this an exercise to reinvent that particular wheel?
There are no new questions, but there may be new answers.
Joined: Aug 26, 2012
I would personally love to use JFreeChart but this is an assignment for a class, and my instructor wants a from-scratch graphing utility. I do not mind scrapping code if there is a better way to do this using built-in classes.
Thank you for the help so far. I rewrote the code into one class and took a lot of inspiration from the Plot Test example. I'm still having trouble getting the graph to display using the test data defined in the assignVals method, although I can see the axes. Right now I am only plotting the x-data vs. y1-data.
The quieter you are, the more you are able to hear.
Joined: Aug 26, 2012
Hi Kemal, you were right! I did get a plot to display, but only sometimes - other times it would just draw straight horizontal/vertical lines. I did rewrite the code so that it makes more sense, but for whatever reason I am having trouble getting the x-Axis results to display. Would anyone mind taking a look?
Note that the teacher assigned an analysis problem to replace the test data. The results should now look like two curves.