Example usage for org.jfree.chart JFreeChart getXYPlot

List of usage examples for org.jfree.chart JFreeChart getXYPlot

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getXYPlot.

Prototype

public XYPlot getXYPlot() 

Source Link

Document

Returns the plot cast as an XYPlot .

Usage

From source file:org.jfree.chart.demo.ChartTiming2.java

/**
 * Runs the test./* ww w .j a va  2s. co  m*/
 */
public void run() {

    this.finished = false;

    // create a dataset...
    final XYDataset data = new SampleXYDataset2(1, 1440);

    // create a scatter chart...
    final boolean withLegend = true;
    final JFreeChart chart = ChartFactory.createScatterPlot("Scatter plot timing", "X", "Y", data,
            PlotOrientation.VERTICAL, withLegend, false, false);

    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new XYDotRenderer());

    final BufferedImage image = new BufferedImage(400, 300, BufferedImage.TYPE_INT_RGB);
    final Graphics2D g2 = image.createGraphics();
    final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 400, 300);

    // set up the timer...
    final Timer timer = new Timer(10000, this);
    timer.setRepeats(false);
    int count = 0;
    timer.start();
    while (!this.finished) {
        chart.draw(g2, chartArea, null, null);
        System.out.println("Charts drawn..." + count);
        if (!this.finished) {
            count++;
        }
    }
    System.out.println("DONE");

}

From source file:mls.FramePlot.java

private JFreeChart createChartMedia(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createXYLineChart("Media campionaria", "n", "en", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    plotMedia = result.getXYPlot();
    ValueAxis axis = plotMedia.getDomainAxis();
    axis.setAutoRange(true);/*from w  w  w  .j a  va 2s .com*/
    axis.setFixedAutoRange(1500);

    axis = plotMedia.getRangeAxis();
    axis.setAutoRange(true);
    axis.setRange(75, 160);
    plotMedia.getRenderer().setSeriesPaint(0, Color.BLUE);
    return result;
}

From source file:com.romraider.logger.ecu.ui.tab.LoggerChartPanel.java

private void addSeries(JFreeChart chart, int index, XYSeries series, int size, Color color) {
    XYDataset dataset = new XYSeriesCollection(series);
    XYPlot plot = chart.getXYPlot();
    plot.setDataset(index, dataset);//from  w  ww . j  a  va 2  s .  c  om
    plot.setRenderer(index, buildScatterRenderer(size, color));
}

From source file:examples.gp.monalisa.gui.EvolutionRunnable.java

public void run() {
    Configuration.reset();/*from   www.  j a va 2  s. c  o  m*/
    try {
        final DrawingGPConfiguration conf = new DrawingGPConfiguration(m_view.getTargetImage());
        JFreeChart chart = m_view.getChart();
        XYSeriesCollection sc = (XYSeriesCollection) chart.getXYPlot().getDataset();
        XYSeries series = sc.getSeries(0);
        series.clear();
        IEventManager eventManager = conf.getEventManager();
        eventManager.addEventListener(GeneticEvent.GPGENOTYPE_EVOLVED_EVENT, new GeneticEventListener() {
            /**
             * Updates the chart in the main view.
             *
             * @param a_firedEvent the event
             */
            public void geneticEventFired(GeneticEvent a_firedEvent) {
                GPGenotype genotype = (GPGenotype) a_firedEvent.getSource();
                int evno = genotype.getGPConfiguration().getGenerationNr();
                if (evno % 25 == 0) {
                    double bestFitness = genotype.getFittestProgram().getFitnessValue();
                    JFreeChart chart = m_view.getChart();
                    XYSeriesCollection sc = (XYSeriesCollection) chart.getXYPlot().getDataset();
                    XYSeries series = sc.getSeries(0);
                    series.add(evno, bestFitness);
                }
            }
        });
        eventManager.addEventListener(GeneticEvent.GPGENOTYPE_NEW_BEST_SOLUTION, new GeneticEventListener() {
            private transient Logger LOGGER2 = Logger.getLogger(EvolutionRunnable.class);
            private DrawingGPProgramRunner gpProgramRunner = new DrawingGPProgramRunner(conf);

            /**
             * Display best solution in fittestChromosomeView's mainPanel.
             *
             * @param a_firedEvent the event
             */
            public void geneticEventFired(GeneticEvent a_firedEvent) {
                GPGenotype genotype = (GPGenotype) a_firedEvent.getSource();
                IGPProgram best = genotype.getAllTimeBest();
                ApplicationData data = (ApplicationData) best.getApplicationData();
                LOGGER2.info("Num Points / Polygons: " + data.numPoints + " / " + data.numPolygons);

                BufferedImage image = gpProgramRunner.run(best);
                Graphics g = m_view.getFittestDrawingView().getMainPanel().getGraphics();
                if (!initView) {
                    m_view.getFittestDrawingView().setSize(204, 200 + 30);
                    m_view.getFittestDrawingView().getMainPanel().setSize(200, 200);
                    initView = true;
                }
                g.drawImage(image, 0, 0, m_view.getFittestDrawingView());
                if (m_view.isSaveToFile()) {
                    int fitness = (int) best.getFitnessValue();
                    String filename = "monalisa_" + NumberKit.niceNumber(fitness, 5, '_') + ".png";
                    java.io.File f = new java.io.File(filename);
                    try {
                        javax.imageio.ImageIO.write(image, "png", f);
                    } catch (java.io.IOException iex) {
                        iex.printStackTrace();
                    }
                }
            }
        });
        GPProblem problem = new DrawingProblem(conf);
        GPGenotype gp = problem.create();
        gp.setVerboseOutput(true);
        while (m_view.isEvolutionActivated()) {
            gp.evolve();
            gp.calcFitness();
            if (gp.getGPConfiguration().getGenerationNr() % 25 == 0) {
                String freeMB = SystemKit.niceMemory(SystemKit.getFreeMemoryMB());
                LOGGER.info("Evolving gen. " + (gp.getGPConfiguration().getGenerationNr()) + ", mem free: "
                        + freeMB + " MB");
            }
        }
        // Create graphical tree from currently fittest image.
        // ---------------------------------------------------
        IGPProgram best = gp.getAllTimeBest();
        int fitness = (int) best.getFitnessValue();
        String filename = "monalisa_" + NumberKit.niceNumber(fitness, 5, '_') + ".png";
        problem.showTree(best, filename);
    } catch (InvalidConfigurationException e) {
        e.printStackTrace();
        System.exit(-1);
    }
}

From source file:org.jfree.chart.demo.SerializationTest1.java

/**
 * Creates a sample chart./*from  w  w w  .  j a va2  s .c  om*/
 * 
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("Serialization Test 1", "Time", "Value",
            dataset, true, true, false);
    final XYPlot plot = result.getXYPlot();
    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds
    return result;
}

From source file:backend.java.ScatterPlot.java

private JFreeChart getChart(XYSeriesCollection dataset, String title, String xAxisTitle, String yAxisTitle,
        Regression[] regressions) {//from   w  w w.j  a v  a 2s .c  o  m
    JFreeChart chart = ChartFactory.createScatterPlot(title, xAxisTitle, yAxisTitle, dataset,
            PlotOrientation.VERTICAL, true, false, false);
    for (Regression regression : regressions) {
        regression.preformRegression(dataset, chart.getXYPlot());
    }

    return chart;
}

From source file:net.sf.mzmine.chartbasics.gestures.ChartGestureDragDiffHandler.java

/**
 * use default orientation or orientation of axis
 * /*ww w. j  a va2  s  .  com*/
 * @param event
 * @return
 */
public Orientation getOrientation(ChartGestureEvent event) {
    ChartEntity ce = event.getEntity();
    if (ce instanceof AxisEntity) {
        JFreeChart chart = event.getChart();
        PlotOrientation plotorient = PlotOrientation.HORIZONTAL;
        if (chart.getXYPlot() != null)
            plotorient = chart.getXYPlot().getOrientation();
        else if (chart.getCategoryPlot() != null)
            plotorient = chart.getCategoryPlot().getOrientation();

        Entity entity = event.getGesture().getEntity();
        if ((entity.equals(Entity.DOMAIN_AXIS) && plotorient.equals(PlotOrientation.VERTICAL))
                || (entity.equals(Entity.RANGE_AXIS) && plotorient.equals(PlotOrientation.HORIZONTAL)))
            orient = Orientation.HORIZONTAL;
        else
            orient = Orientation.VERTICAL;
    }
    return orient;
}

From source file:fr.paris.lutece.plugins.form.utils.FormUtils.java

/**
 * create a JFreeChart Graph function of the statistic form submit
 * @param listStatistic the list of statistic of form submit
 * @param strLabelX the label of axis x//  w w  w.  j  ava2  s. c om
 * @param strLableY the label of axis x
 * @param strTimesUnit the times unit of axis x(Day,Week,Month)
 * @return a JFreeChart Graph function of the statistic form submit
 */
public static JFreeChart createXYGraph(List<StatisticFormSubmit> listStatistic, String strLabelX,
        String strLableY, String strTimesUnit) {
    XYDataset xyDataset = createDataset(listStatistic, strTimesUnit);
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(EMPTY_STRING, strLabelX, strLableY, xyDataset,
            false, false, false);
    jfreechart.setBackgroundPaint(Color.white);

    XYPlot xyplot = jfreechart.getXYPlot();

    //xyplot.setBackgroundPaint(Color.gray);
    //xyplot.setRangeGridlinesVisible(true);
    xyplot.setBackgroundPaint(Color.white);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);

    //      DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(  );
    //      dateaxis.setLowerMargin(0);
    //      DateFormat formatter = new SimpleDateFormat("d-MMM-yyyy");
    //      dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY,7,formatter));
    //dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY,7));
    //dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY,7));

    //dateaxis.setMinimumDate((Date)listStatistic.get(0).getTimesUnit());
    //dateaxis.setMaximumDate((Date)listStatistic.get(listStatistic.size()-1).getTimesUnit());

    //dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH,1));
    //dateaxis.setTickUnit(new DateTickUnit(1, 1, DateFormat.getDateInstance(DateFormat.SHORT, Locale.FRENCH)));
    //dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1, new SimpleDateFormat("MM/YY")));
    //dateaxis.setVerticalTickLabels( true );
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setSeriesFillPaint(0, Color.RED);
    renderer.setUseFillPaint(true);

    //      renderer.setToolTipGenerator( new StandardXYToolTipGenerator( "{0} {1} {2}",
    //            DateFormat.getDateInstance( DateFormat.SHORT, Locale.FRENCH ), NumberFormat.getInstance(  ) ) );
    //
    //      ChartRenderingInfo info = new ChartRenderingInfo( new StandardEntityCollection(  ) );
    return jfreechart;
}

From source file:ws.moor.bt.gui.charts.RawDownloadRate.java

private JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Download Rate", "Time", "KB/s", dataset, false,
            false, false);//w  w  w  . j  a v a  2 s  . c om
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

    return chart;
}

From source file:com.sigueros.charts.LinearRegressionExample.java

/**
 * Creates a chart//w w  w .jav  a  2  s  . c  om
 */

private JFreeChart createChart(String title) {

    TimeSeriesCollection dataColumnsCollection = createDatasetColumns();
    TimeSeriesCollection dataLinearCollection = createDatasetLinear();

    JFreeChart chart = ChartFactory.createXYBarChart(title, "Ao", true, "granos/m3", dataColumnsCollection,
            PlotOrientation.VERTICAL, true, false, false);

    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer linearRenderer = new XYLineAndShapeRenderer(true, false);
    plot.setDataset(1, dataLinearCollection);
    plot.setRenderer(1, linearRenderer);

    return chart;

}