All pastes #807472 Raw Edit

Someone

public java v1 · immutable
·published 2007-12-06 18:56 UTC
rendered paste body
 package javaapplication10; /**  * This class plots the specified X,Y data on a scatter plot  * An external window is created in which the plot can be zoomed,  * printed, etc.   *   * This class uses the Jfree Chart library which is available for   * public use under the GNU Lesser Public License   *   * @author Ajay Surie  * 03-510  */   import java.awt.GradientPaint; import java.awt.Color; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.data.xy.XYDataset; import org.jfree.chart.renderer.xy.StandardXYItemRenderer; import org.jfree.chart.renderer.xy.XYDotRenderer;   import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; import java.util.*;  public class Plotter extends ApplicationFrame {      private JFreeChart myChart = null;      /**      * Constructs a new Plotter based on the specified parameters      * @param title  the frame title.      * @param seriesName the name of the series to be plotted      * @param xName the name of the x data       * @param yName the name of the y data      * @param x the x coordinates to be plotted       * @param y the y coordinates to be plotted      */     public Plotter(ArrayList<Double> x1, ArrayList<Double> y1) {     super("Polynomial regression by xxx");                                  XYSeries series = new XYSeries("seriesName");                 for(Double d : x1){                      series.add(d,2.0);                   }         //	for(int i=0;i<x1.length;i++) //	    series.add(x1[i],y1[i]);         XYDataset data = new XYSeriesCollection(series);         myChart = createChart(data,"Polynomial regression using least square method","t-value","z-value");         ChartPanel chartPanel = new ChartPanel(myChart); 	myChart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.green)); 	chartPanel.setPreferredSize(new java.awt.Dimension(600, 600));         chartPanel.setVerticalAxisTrace(true);         chartPanel.setHorizontalAxisTrace(true); //        chartPanel.setVerticalZoom(true); //        chartPanel.setHorizontalZoom(true);         setContentPane(chartPanel);     }      /**      * Creates a chart.      *       * @param dataset  the dataset.      *       * @return The chart.      */     private JFreeChart createChart(XYDataset dataset, String title, String xName,String yName) {         JFreeChart chart = ChartFactory.createScatterPlot(             title,             xName, yName, dataset,             PlotOrientation.VERTICAL,             true,  // legend             false,  // tooltips             false  // urls         );         XYPlot plot = chart.getXYPlot(); 	plot.setRenderer(new XYDotRenderer()); 	plot.setDomainCrosshairVisible(true); 	plot.setRangeCrosshairVisible(true);         NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();         domainAxis.setAutoRangeIncludesZero(false);         return chart;     }          /**      * Sets the plot type based on the specified preferences      * @param dot True if the plot is a dot plot      * @param shapes_lines True if the plot is a plot with shapes and lines      */     public void setPlotType(boolean dot,boolean shapes_lines){ 	if(dot) 	    myChart.getXYPlot().setRenderer(new XYDotRenderer());  	else if(shapes_lines) 	    myChart.getXYPlot().setRenderer(new StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer.SHAPES_AND_LINES)); 	else 	    myChart.getXYPlot().setRenderer(new StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer.SHAPES));     }      /**      * Renders the chart in a new window      */     public void renderChart(){ 	this.pack();         RefineryUtilities.centerFrameOnScreen(this);         this.setVisible(true);     }          }