Why doesn't JFreeCharts correctly connect the points in my xy-line graph?

Posted by Javajava on Stack Overflow See other posts from Stack Overflow or by Javajava
Published on 2010-05-12T20:39:44Z Indexed on 2010/05/12 20:44 UTC
Read the original article Hit count: 203

Filed under:
|
|
|
|

/Each letter A,T,G,C represents a direction for the plot to graph. Specifically, “A” means move right, “T” is move down, “C” is move up, and “G” is move left. When the applet reads A,T,C, it plots the graph correctly. However, when I plot G, the graph is messed up. When I input "ACACACA," the graph is like a rising staircase. When I input "gtgtgt," the graph should look like a staircase, but it looks like a lightning bolt instead/

/This is all one code... i don't know why it's all split up like this:/

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.Scanner.*;
import java.jfree.chart.*;
import java.jfree.data.xy.*;
import java.jfree.chart.plot.PlotOrientation;
public class If_Graph extends Applet implements ActionListener{

Panel panel;
TextArea textarea, outputArea;
Button move;
String thetext;
Scanner reader = new Scanner(System.in);
String thetext2;
int size,p,q;
int x,y;

public void init(){

    setSize(500,500); //set size of applet

    panel = new Panel();
    add(panel);
    setVisible(true);
    textarea= new TextArea(10,20);
    add(textarea);

    move=new Button("Graph");
    move.addActionListener(this);
    add(move);
}

public void actionPerformed(ActionEvent e)
{
 XYSeries series = new XYSeries("DNA Walk");

    x= 0; y = 0;
    series.add(x,y);

    if(e.getSource() == move)
    {
        thetext=textarea.getText(); //the text is the DNA bases pasted
        thetext=thetext.replaceAll(" ",""); //removes spaces
        thetext2 = "";

        for(int i=0; i<thetext.length(); i++)
       {
        char a = thetext.charAt(i);

        switch (a)
        {
            case 'A': //moves right
               x+=1; y+=0;
               series.add(x,y);
                break;
            case 'a':
              x+=1;y+=0;
              series.add(x,y);
                  break;
            case 'C': //moves up
              x+=0; y+=1;
              series.add(x,y);
                break;
            case 'c':
              x+=0; y+=1;
              System.out.println(x + "," + y);
              series.add(x,y);
                break;
            case 'G': //move left
              x-=1; y+=0;
              series.add(x,y);
              System.out.println("G is: "+ x +"," +y);
                break;
            case 'g':
              x-=1; y+=0;
              System.out.println("g is: " +x + "," + y);
              series.add(x,y);
                break;
            case 'T': //move down
              x+=0; y-=1;
              series.add(x,y);
               System.out.println("T is: "+ x +"," +y);
                break;
            case 't':
              x+=0; y-=1;
             series.add(x,y);
              System.out.println("t is: "+ x +"," +y);
                break;
            default: // series.add(0,0);
                break;
        }
        }
    XYDataset xyDataset = new XYSeriesCollection(series);

JFreeChart chart = ChartFactory.createXYLineChart ("DNA Random Walk", "", "", xyDataset, PlotOrientation.VERTICAL, true, true, false); ChartFrame frame1=new ChartFrame("DNA Random Walk",chart); frame1.setVisible(true); frame1.setSize(300,300); outputArea.setText(thetext2); } } }

© Stack Overflow or respective owner

Related posts about java

Related posts about jfreechart