Example usage for org.jfree.chart ChartFactory createXYLineChart

List of usage examples for org.jfree.chart ChartFactory createXYLineChart

Introduction

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

Prototype

public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset) 

Source Link

Document

Creates a line chart (based on an XYDataset ) with default settings.

Usage

From source file:algoritmosdeordenamiento.Grafica.java

public void creaYmuestraGrafica() {

    this.grafica = ChartFactory.createXYLineChart(nombre, tituloEjeX, tituloEjeY, series);

    // utilizar un panel especial dentro de jfreechart
    ChartFrame panel = new ChartFrame("grafica", grafica);
    panel.pack();/*from  w  w  w  .j a va  2  s .  c  om*/
    panel.setVisible(true);

}

From source file:cz.cuni.mff.d3s.spl.demo.libselection.JFreeChartPlotter.java

@Override
public void renderPlotToPng(List<Pair<Long, Long>> dataPairs, int width, int height, OutputStream output)
        throws IOException {

    XYDataset dataset = getDatasetFromPairList(dataPairs);
    JFreeChart chart = ChartFactory.createXYLineChart("Line Chart Demo", "X", "Y", dataset);

    ChartUtilities.writeChartAsPNG(output, chart, width, height);
}

From source file:controller.DrawCurve.java

private JPanel createChart() {
    String chartTitle = "Camera Response Curve";
    String xAxisLabel = "log Exposure G(Z)";
    String yAxisLabel = "Intensity pixel Z";

    XYDataset dataset = createDataset();

    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, xAxisLabel, yAxisLabel, dataset);

    //Set custom color and thickness for line curve
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

    // sets paint color for each series
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GREEN);
    renderer.setSeriesPaint(2, Color.BLUE);

    // sets thickness for series (using strokes)
    renderer.setSeriesStroke(0, new BasicStroke(1.5f));
    renderer.setSeriesStroke(1, new BasicStroke(1.5f));
    renderer.setSeriesStroke(2, new BasicStroke(1.5f));

    XYPlot plot = chart.getXYPlot();//from  w  w w .j  a  v  a 2s . c  om
    plot.setRenderer(renderer);

    return new ChartPanel(chart);
}

From source file:net.sf.mzmine.chartbasics.gui.javafx.demo.FXChartGestureDemo.java

@Override
public void start(Stage stage) throws Exception {
    XYDataset dataset = createDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Random", "i", "r", createDataset());
    EChartViewer canvas = new EChartViewer(chart);
    StackPane stackPane = new StackPane();
    stackPane.getChildren().add(canvas);
    stage.setScene(new Scene(stackPane));
    stage.setTitle("Chart gesture demo");
    stage.setWidth(700);/* w ww  .jav  a 2 s .co m*/
    stage.setHeight(390);
    stage.show();
}

From source file:serial.LineChart.java

/**
 * Creates a jFreeChart lineChart//ww  w .  j  a  v a2s. c om
 *
 * @param graphName Name of the chart
 * @param xAxisLabel X-Axis Label
 * @param yAxisLabel Y-Axis Label
 * @param bufferSize Max number of data points to display on the graph at a
 * time. Bear in mind that larger values (>30,000) can begin to cause
 * problems with lag.
 */
public LineChart(String graphName, String xAxisLabel, String yAxisLabel, int bufferSize) {
    initComponents();
    defaultSeries = new XYSeries(graphName);
    defaultSeries.setMaximumItemCount(bufferSize);
    defaultDataset = new XYSeriesCollection(defaultSeries);
    defaultChart = ChartFactory.createXYLineChart(graphName, xAxisLabel, yAxisLabel, defaultDataset);
    graph = new ChartPanel(defaultChart);

    this.add(graph, BorderLayout.CENTER);
    graph.setVisible(true);

}

From source file:org.chocosolver.gui.panels.ObjectivePanel.java

public ObjectivePanel(GUI frame) {
    super(frame);
    isOpt = solver.getObjectiveManager().getPolicy() != ResolutionPolicy.SATISFACTION;
    isMax = solver.getObjectiveManager().getPolicy() == ResolutionPolicy.MAXIMIZE;
    objective = new XYSeries("Best value");
    bounds = new XYSeries(isMax ? "Upper bound" : "Lower bound");
    XYSeriesCollection coll = new XYSeriesCollection();
    coll.addSeries(objective);//from  w  ww  .j  a  v  a  2 s.  c  om
    coll.addSeries(bounds);

    JFreeChart dchart = ChartFactory.createXYLineChart("Objective", "Nodes", "Objective", coll);

    this.setChart(dchart);
    if (isOpt) {
        solver.plugMonitor(this);
    }
}

From source file:de.hs.mannheim.modUro.diagram.JCellCountDiagram.java

protected JFreeChart createChart(XYDataset dataset, String name) {
    String title = name;/*from  www .  j av a 2s  .c  o  m*/

    JFreeChart xyLineChart = ChartFactory.createXYLineChart(title, // title
            "t", // x-axis label
            "n", // y-axis label
            dataset);

    String fontName = "Palatino";
    xyLineChart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));

    XYPlot plot = (XYPlot) xyLineChart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    plot.getRangeAxis().setLowerMargin(0.0);
    // plot.getRangeAxis().setRange(0.0, 1.01);
    plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    xyLineChart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14));
    xyLineChart.getLegend().setFrame(BlockBorder.NONE);
    xyLineChart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER);
    XYItemRenderer r = plot.getRenderer();
    // set the default stroke for all series
    int i = 0;
    for (String celltype : getTimeSeries().getDataSeriesNames()) {
        r.setSeriesPaint(i, CellTypeColor.getColor(celltype));
        i++;
    }
    r.setSeriesPaint(i, Color.BLACK);
    return xyLineChart;
}

From source file:de.hs.mannheim.modUro.controller.diagram.DiagramController.java

/**
 * Creates JFreeChart. XYLineDiagram.// ww  w  . j a v a 2s .  co m
 *
 * @param dataset
 * @return
 */
protected JFreeChart createChart(XYDataset dataset, String metricTypeName) {
    String title = metricTypeName;

    JFreeChart xyLineChart = ChartFactory.createXYLineChart(title, // title
            "t", // x-axis label
            "f", // y-axis label
            dataset);

    String fontName = "Palatino";
    xyLineChart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));

    XYPlot plot = (XYPlot) xyLineChart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    plot.getRangeAxis().setLowerMargin(0.0);
    plot.getRangeAxis().setRange(0.0, 1.01);
    plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    xyLineChart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14));
    xyLineChart.getLegend().setFrame(BlockBorder.NONE);
    xyLineChart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER);
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(false);
        renderer.setDrawSeriesLineAsPath(true);
        // set the default stroke for all series
        renderer.setAutoPopulateSeriesStroke(false);
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesPaint(1, new Color(24, 123, 58));
        renderer.setSeriesPaint(2, new Color(149, 201, 136));
        renderer.setSeriesPaint(3, new Color(1, 62, 29));
        renderer.setSeriesPaint(4, new Color(81, 176, 86));
        renderer.setSeriesPaint(5, new Color(0, 55, 122));
        renderer.setSeriesPaint(6, new Color(0, 92, 165));
    }

    return xyLineChart;
}

From source file:net.sf.mzmine.chartbasics.gui.swing.demo.SwingChartGestureDemo.java

public SwingChartGestureDemo() {
    setSize(800, 600);//from   w ww.j  a va  2  s. c  om
    setTitle("Chart gesture test");
    XYDataset dataset = createDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Random", "i", "r", createDataset());
    EChartPanel canvas = new EChartPanel(chart);
    StackPane stackPane = new StackPane();
    getContentPane().add(canvas, BorderLayout.CENTER);
}

From source file:utlis.HistogramPlot.java

public JFreeChart plotColorChart(ArrayList<int[]> histograms) {

    XYSeries xysRed = new XYSeries("Red");
    XYSeries xysGreen = new XYSeries("Grean");
    XYSeries xysBlue = new XYSeries("blue");

    for (int i = 0; i < histograms.get(0).length; i++) {

        xysRed.add(i, histograms.get(0)[i]);
        xysBlue.add(i, histograms.get(2)[i]);
        xysGreen.add(i, histograms.get(1)[i]);
    }/*  w w  w .  j  a va 2 s  .  co  m*/

    XYSeriesCollection collection = new XYSeriesCollection();
    collection.addSeries(xysRed);
    collection.addSeries(xysBlue);
    collection.addSeries(xysGreen);

    JFreeChart chart = ChartFactory.createXYLineChart("Histogram", "Color Value", "Pixel count", collection);
    try {
        ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 500, 300);
    } catch (IOException ex) {
        Logger.getLogger(HistogramPlot.class.getName()).log(Level.SEVERE, null, ex);
    }
    return chart;
}