Example usage for org.jfree.chart JFreeChart JFreeChart

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

Introduction

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

Prototype

public JFreeChart(String title, Plot plot) 

Source Link

Document

Creates a new chart with the given title and plot.

Usage

From source file:org.gvsig.remotesensing.scatterplot.gui.ChartScaterPlotPanel.java

/**
 *    Metodo que construye el grafico inicialmente. Antes de construirlo, llama a
 *    setDataChart() para cargar los datos a representar
 *
 * *//*from www  . j  ava2s  . c om*/
private void createChart(Color colorChart, Color colorBackground, Color colorExternal) {

    NumberAxis domainAxis = new NumberAxis(PluginServices.getText(this, "banda") + " " + (bandaX + 1));
    domainAxis.setAutoRangeIncludesZero(false);
    NumberAxis rangeAxis = new NumberAxis(PluginServices.getText(this, "banda") + " " + (bandaY + 1));
    rangeAxis.setAutoRangeIncludesZero(false);

    // Se cargan los datos antes de construir el grafico
    setDataChart(fLayer);
    plot = new ScatterPlotChart(this.data, domainAxis, rangeAxis);
    chart = new JFreeChart(PluginServices.getText(this, "diagrama_dispersion"), plot);
    data = null;
    chart.getRenderingHints().clear();
    chart.setBackgroundPaint(colorExternal);
    plot.setPaint(colorChart);
    plot.setBackgroundPaint(colorBackground);
}

From source file:playground.dgrether.analysis.charts.DgDeltaUtilsModeGroupChart.java

/**
 * @see playground.dgrether.analysis.charts.interfaces.DgChart#createChart()
 */// w w  w. j av a  2 s .com
@Override
public JFreeChart createChart() {
    XYPlot plot = new XYPlot(this.dataset, new NumberAxis("Income"), new NumberAxis("Delta utils"), null);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true);
    plot.setRenderer(renderer);

    JFreeChart jchart = new JFreeChart("", plot);
    return jchart;
}

From source file:LoggerGUI.DataLogger.java

public DataLogger(String title) {
    super(title);
    initialize();/*w  w  w.  j av a 2s. c om*/

    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.datasets = new TimeSeriesCollection[INPUT_COUNT];

    this.lastValue[0] = 100.0;
    this.lastValue[1] = 100.0;
    this.lastValue[2] = 100.0;
    this.lastValue[3] = 100.0;
       
        
        
       
        
    final TimeSeries s0 = new TimeSeries("A0", Millisecond.class);
    final TimeSeries s1 = new TimeSeries("A1", Millisecond.class);
    final TimeSeries s2 = new TimeSeries("A2", Millisecond.class);
    final TimeSeries s3 = new TimeSeries("A3", Millisecond.class);
        
        
        
    this.datasets[0] = new TimeSeriesCollection(s0);
    this.datasets[1] = new TimeSeriesCollection(s1);
    this.datasets[2] = new TimeSeriesCollection(s2);
    this.datasets[3] = new TimeSeriesCollection(s3);
       
        

    final NumberAxis rangeAxis = new NumberAxis("ADC Signal");

    rangeAxis.setAutoRangeIncludesZero(false);
    XYPlot subplot;

        
    XYLineAndShapeRenderer renderer =  new XYLineAndShapeRenderer(true,false);
    XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(true,false);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true,false);
    XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer(true,false);
        
    subplot= new XYPlot(
            new TimeSeriesCollection(), null, rangeAxis, new XYLineAndShapeRenderer(true,false)
    );
       
    plot.add(subplot);
       
        
        
    renderer.setBaseShapesVisible(false);
    renderer.setSeriesPaint(0, Color.red);
    subplot.setDataset(0,datasets[0]);
    subplot.setRenderer(0,renderer);
        
        
    renderer1.setBaseShapesVisible(false);
    renderer1.setSeriesPaint(0, Color.blue);
    subplot.setDataset(1,datasets[1]);
    subplot.setRenderer(1,renderer1);
        
        
    renderer2.setBaseShapesVisible(false);
    renderer2.setSeriesPaint(0, Color.black);
    subplot.setDataset(2,datasets[2]);
    subplot.setRenderer(2,renderer2);
        
    subplot.getRendererForDataset(subplot.getDataset(0)).setSeriesPaint(0, Color.red); 
    subplot.getRendererForDataset(subplot.getDataset(1)).setSeriesPaint(1, Color.blue);
    subplot.getRendererForDataset(subplot.getDataset(2)).setSeriesPaint(2, Color.black);
        
    renderer3.setBaseShapesVisible(false);
    renderer3.setSeriesPaint(0, Color.green);
    subplot.setDataset(3,datasets[3]);
    subplot.setRenderer(3,renderer3);
        
        
        
    final JFreeChart chart = new JFreeChart("Data Logger", plot);
    chart.setBorderPaint(Color.black);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);
        
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(20000.0);  // 60 seconds

    
    final JPanel content = new JPanel(new BorderLayout());

    final ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    final JPanel buttonPanel = new JPanel(new FlowLayout());
        
    content.add(buttonPanel, BorderLayout.NORTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(600, 600));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(content);
        
        
}

From source file:playground.dgrether.analysis.charts.DgTravelTimeCalculatorChart.java

@Override
public JFreeChart createChart() {
    XYSeriesCollection dataset = this.createDataSet();
    XYPlot plot = new XYPlot();
    DgAxisBuilder axisBuilder = new DgDefaultAxisBuilder();
    ValueAxis xAxis = axisBuilder.createValueAxis("Simulation Time");
    //    xAxis.setRange(this.controllerConfig.getFirstIteration(), this.controllerConfig.getLastIteration() + 2);
    ValueAxis yAxis = axisBuilder.createValueAxis("Travel Time");
    //    yAxis.setRange(-0.05, 0.3);
    //    xAxis.setVisible(false);
    //    xAxis.setFixedAutoRange(1.0);
    plot.setDomainAxis(xAxis);//from   ww w  .  j a  va  2s.  c  o  m
    plot.setRangeAxis(yAxis);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, false);
    renderer2.setSeriesItemLabelsVisible(0, true);
    //    renderer2.setSeriesItemLabelGenerator(0, this.labelGenerator);
    plot.setDataset(0, dataset);
    renderer2.setSeriesStroke(0, new BasicStroke(1.0f));
    renderer2.setSeriesOutlineStroke(0, new BasicStroke(1.0f));
    renderer2.setSeriesPaint(0, colorScheme.getColor(1, "a"));
    renderer2.setSeriesStroke(1, new BasicStroke(1.0f));
    renderer2.setSeriesOutlineStroke(1, new BasicStroke(1.0f));
    renderer2.setSeriesPaint(1, colorScheme.getColor(2, "a"));
    renderer2.setSeriesStroke(2, new BasicStroke(1.0f));
    renderer2.setSeriesOutlineStroke(2, new BasicStroke(1.0f));
    renderer2.setSeriesPaint(2, colorScheme.getColor(3, "a"));
    renderer2.setSeriesStroke(3, new BasicStroke(1.0f));
    renderer2.setSeriesOutlineStroke(3, new BasicStroke(1.0f));
    renderer2.setSeriesPaint(3, colorScheme.getColor(4, "a"));

    plot.setRenderer(0, renderer2);

    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    //    chart.removeLegend();
    return chart;
}

From source file:playground.dgrether.analysis.charts.DgAvgDeltaMoneyGroupChart.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("Income [Chf / Year]");
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Money [Chf]");
    plot.setDomainAxis(xAxis);/*  www. j  a va 2 s. c  o m*/
    plot.setRangeAxis(yAxis);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    renderer2.setSeriesItemLabelsVisible(0, true);
    renderer2.setSeriesItemLabelGenerator(0, this.labelGenerator);
    plot.setDataset(0, this.dataset);
    renderer2.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer2.setSeriesOutlineStroke(0, new BasicStroke(3.0f));
    renderer2.setSeriesPaint(0, colorScheme.getColor(1, "a"));
    plot.setRenderer(0, renderer2);

    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    return chart;
}

From source file:org.ietr.preesm.mapper.ui.BestCostPlotter.java

/**
 * Creates a chart./*from  w w w  .  j  a v  a2s.c om*/
 * 
 * @return A chart.
 */
private JFreeChart createChart(String title) {

    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.datasets = new TimeSeriesCollection[subplotCount];

    for (int i = 0; i < subplotCount; i++) {
        this.lastValue[i] = 100.0;
        final TimeSeries series = new TimeSeries("Real Time", Millisecond.class);
        this.datasets[i] = new TimeSeriesCollection(series);
        final NumberAxis rangeAxis = new NumberAxis("Schedule");
        rangeAxis.setAutoRangeIncludesZero(false);
        final XYPlot subplot = new XYPlot(this.datasets[i], null, rangeAxis, new XYLineAndShapeRenderer());

        subplot.setBackgroundPaint(Color.white);
        subplot.setDomainGridlinePaint(Color.lightGray);
        subplot.setRangeGridlinePaint(Color.lightGray);
        plot.add(subplot);
    }

    final JFreeChart chart = new JFreeChart(title, plot);

    chart.removeLegend();
    // chart.getLegend().setPosition(RectangleEdge.BOTTOM);

    chart.setBorderPaint(Color.lightGray);
    chart.setBorderVisible(true);

    Paint p = GanttPlotter.getBackgroundColorGradient();
    chart.setBackgroundPaint(p);

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.black);

    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);

    return chart;

}

From source file:com.compomics.cell_coord.gui.controller.computation.ComputationDataController.java

/**
 *
 * @param track/*from w w w  .  j a v  a 2  s  . c  o m*/
 */
private void plotCoordinatesTime(Track track) {
    Double[][] coordinates = track.getCoordinates();
    Double[][] transpose2DArray = ComputationUtils.transpose2DArray(coordinates);
    double[] timeIndexes = track.getTimeIndexes();
    double[] xCoordinates = ArrayUtils.toPrimitive(ComputationUtils.excludeNullValues(transpose2DArray[0]));
    XYSeries xtSeries = JFreeChartUtils.generateXYSeries(timeIndexes, xCoordinates);
    XYSeriesCollection xtSeriesCollection = new XYSeriesCollection(xtSeries);
    XYItemRenderer renderer = new StandardXYItemRenderer();
    NumberAxis xAxis = new NumberAxis("x");
    XYPlot xTPlot = new XYPlot(xtSeriesCollection, null, xAxis, renderer);
    NumberAxis yAxis = new NumberAxis("y");
    double[] yCoordinates = ArrayUtils.toPrimitive(ComputationUtils.excludeNullValues(transpose2DArray[1]));
    XYSeries ytSeries = JFreeChartUtils.generateXYSeries(timeIndexes, yCoordinates);
    XYSeriesCollection ytSeriesCollection = new XYSeriesCollection(ytSeries);
    XYPlot yTPlot = new XYPlot(ytSeriesCollection, null, yAxis, renderer);
    // domain axis
    NumberAxis domainAxis = new NumberAxis("time index");
    CombinedDomainXYPlot combinedDomainXYPlot = new CombinedDomainXYPlot(domainAxis);
    combinedDomainXYPlot.setRenderer(new XYLineAndShapeRenderer());
    combinedDomainXYPlot.add(xTPlot);
    combinedDomainXYPlot.add(yTPlot);
    combinedDomainXYPlot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart combinedChart = new JFreeChart("temp. evolution", combinedDomainXYPlot);
    ChartPanel chartPanel = new ChartPanel(combinedChart);
    computationDataPanel.getxYParentPanel().removeAll();
    computationDataPanel.getxYParentPanel().add(chartPanel, gridBagConstraints);
    computationDataPanel.getxYParentPanel().revalidate();
    computationDataPanel.getxYParentPanel().repaint();
}

From source file:edu.ucla.stat.SOCR.chart.demo.BoxAndWhiskerChartDemo2.java

/**
 * Creates a sample chart.//  w w  w  .  j a v a2s . co m
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(BoxAndWhiskerCategoryDataset dataset) {

    CategoryAxis domainAxis = new CategoryAxis(null);
    NumberAxis rangeAxis = new NumberAxis(rangeLabel);
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer);
    JFreeChart chart = new JFreeChart(chartTitle, plot);
    plot.setOrientation(PlotOrientation.HORIZONTAL);

    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    renderer.setLegendItemLabelGenerator(
            new SOCRCategoryCellLabelGenerator(dataset, values_storage, SERIES_COUNT, CATEGORY_COUNT));

    //columnCount -- category count
    //RowCount -- serie count

    domainAxis.setLowerMargin(0.44);
    domainAxis.setUpperMargin(0.44);
    if (dataset.getColumnCount() == 1)
        renderer.setItemMargin(0.5);
    //   domainAxis.setCategoryMargin(domainAxis.getCategoryMargin()*2);
    /*         
    System.out.println("1lowerMargin="+domainAxis.getLowerMargin());
    System.out.println("ItemMargin="+renderer.getItemMargin());
    System.out.println("CategoryMargin="+domainAxis.getCategoryMargin());*/

    renderer.setItemMargin(renderer.getItemMargin() * 2);

    /*System.out.println("2lowerMargin="+domainAxis.getLowerMargin());
    System.out.println("ItemMargin="+renderer.getItemMargin());
    System.out.println("CategoryMargin="+domainAxis.getCategoryMargin());*/

    return chart;

}

From source file:org.openmicroscopy.shoola.util.ui.graphutils.ScatterPlot.java

/** 
 * Creates the chart.//from   ww  w.j a v a2  s .c o m
 * @see ChartObject#createChar()
 */
void createChart() {
    PointRenderer renderer = new PointRenderer(colours, shapes);
    XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
    if (backgroundImage != null) {
        plot.setRangeGridlinesVisible(false);
        plot.setDomainGridlinesVisible(false);
        plot.setBackgroundImage(backgroundImage);
    }
    chart = new JFreeChart(title, plot);
}

From source file:org.openmicroscopy.shoola.util.ui.graphutils.HistogramPlot.java

/** 
 * Creates the chart.//from   w  ww  . j  av  a2  s .c o m
 * @see ChartObject#createChar()
 */
void createChart() {
    HistogramBarRenderer renderer = new HistogramBarRenderer(colours);
    for (int i = 0; i < colours.size(); i++)
        renderer.setSeriesPaint(i, colours.get(i));
    XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
    if (backgroundImage != null) {
        plot.setRangeGridlinesVisible(false);
        plot.setDomainGridlinesVisible(false);
        plot.setBackgroundImage(backgroundImage);
    }
    chart = new JFreeChart(title, plot);
}