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, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

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

Usage

From source file:org.samjoey.graphing.GraphUtility.java

public static HashMap<String, ChartPanel> getGraphs(LinkedList<Game> games) {
    HashMap<String, XYSeriesCollection> datasets = new HashMap<>();
    for (int j = 0; j < games.size(); j++) {
        Game game = games.get(j);/*from   w  ww . j a  v  a  2s.  co  m*/
        if (game == null) {
            continue;
        }
        for (String key : game.getVarData().keySet()) {
            if (datasets.containsKey(key)) {
                try {
                    datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
                } catch (Exception e) {
                }
            } else {
                datasets.put(key, new XYSeriesCollection());
                datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
            }
        }
    }
    HashMap<String, ChartPanel> chartPanels = new HashMap<>();
    for (String key : datasets.keySet()) {
        JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title
                "X", // x axis label
                "Y", // y axis label
                datasets.get(key), // data
                PlotOrientation.VERTICAL, false, // include legend
                true, // tooltips
                false // urls
        );
        XYPlot plot = chart.getXYPlot();
        XYItemRenderer rend = plot.getRenderer();
        for (int i = 0; i < games.size(); i++) {
            Game g = games.get(i);
            if (g.getWinner() == 1) {
                rend.setSeriesPaint(i, Color.RED);
            }
            if (g.getWinner() == 2) {
                rend.setSeriesPaint(i, Color.BLACK);
            }
            if (g.getWinner() == 0) {
                rend.setSeriesPaint(i, Color.PINK);
            }
        }
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanels.put(key, chartPanel);
    }
    return chartPanels;
}

From source file:intelligentWebAlgorithms.util.gui.XyGui.java

public XyGui(String title, double[] x, double[] y) {

    super(title);

    errMsg = new StringBuilder();
    setLoopInt(x.length);//from   w ww .  j  a  v a 2 s.c  om

    if (checkX(x) && checkY(x.length, y)) {

        XYSeries xydata = new XYSeries(title);

        for (int i = 0; i < loopInt; i++) {
            xydata.add(x[i], y[i]);
        }

        XYSeriesCollection xycollection = new XYSeriesCollection(xydata);

        final JFreeChart chart = ChartFactory.createXYLineChart(title + " (XY Plot)", "X", "Y", xycollection,
                PlotOrientation.VERTICAL, true, true, false);

        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);
    } else {
        System.err.println(errMsg.toString());
    }
}

From source file:br.com.una.apa.p02e01.Graph.java

/**
 * Creates a chart./*  www .  j  ava2 s .  co  m*/
 * 
 * @param dataset
 *            the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Tam Vetor (N) X Numero de operacoes (OP)",
            // chart title
            "TAM VETOR (N)", // x axis label
            "OPERACOES OP", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tool tips
            false // urls
    );

    return chart;
}

From source file:com.rapidminer.gui.viewer.ROCChartPlotter.java

private JFreeChart createChart(XYDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            null, // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );//from   ww  w.  j a  v  a2  s.c  o m

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    ValueAxis valueAxis = plot.getRangeAxis();
    valueAxis.setLabelFont(PlotterAdapter.LABEL_FONT_BOLD);
    valueAxis.setTickLabelFont(PlotterAdapter.LABEL_FONT);

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLabelFont(PlotterAdapter.LABEL_FONT_BOLD);
    domainAxis.setTickLabelFont(PlotterAdapter.LABEL_FONT);

    DeviationRenderer renderer = new DeviationRenderer(true, false);
    Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    if (dataset.getSeriesCount() == 1) {
        renderer.setSeriesStroke(0, stroke);
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesFillPaint(0, Color.RED);
    } else if (dataset.getSeriesCount() == 2) {
        renderer.setSeriesStroke(0, stroke);
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesFillPaint(0, Color.RED);

        renderer.setSeriesStroke(1, stroke);
        renderer.setSeriesPaint(1, Color.BLUE);
        renderer.setSeriesFillPaint(1, Color.BLUE);
    } else {
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            renderer.setSeriesStroke(i, stroke);
            Color color = colorProvider.getPointColor((double) i / (double) (dataset.getSeriesCount() - 1));
            renderer.setSeriesPaint(i, color);
            renderer.setSeriesFillPaint(i, color);
        }
    }
    renderer.setAlpha(0.12f);
    plot.setRenderer(renderer);

    // legend settings
    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        legend.setPosition(RectangleEdge.TOP);
        legend.setFrame(BlockBorder.NONE);
        legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
        legend.setItemFont(PlotterAdapter.LABEL_FONT);
    }
    return chart;
}

From source file:org.vimarsha.ui.TimeSlicedClassiferForm.java

private JFreeChart createChart(XYSeriesCollection dataSet, String chartTitle) {
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, "Time slice number", "Classification",
            dataSet, PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = chart.getXYPlot();/*from www.  j  a  v a2s. c o  m*/
    NumberAxis range = (NumberAxis) plot.getRangeAxis();

    range.setRange(0, 1.1);
    TickUnits units = new TickUnits();
    units.add(new NumberTickUnit(0));
    units.add(new NumberTickUnit(0.5));
    units.add(new NumberTickUnit(1));

    range.setStandardTickUnits(units);
    range.setNumberFormatOverride(new DecimalFormat() {
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
            if (number == 1)
                return toAppendTo.append("badfs");
            else if (number == 0.5)
                return toAppendTo.append("badma");
            else
                return toAppendTo.append("good");
        }
    });

    return chart;
}

From source file:com.devoteam.srit.xmlloader.gui.frames.JFrameRunProfile.java

private void refreshGraph(int type) {
    ArrayList<Point> vector = runProfile.getPoints();
    this.jPanelGraph.removeAll();

    if (type == 1) // delay graph
    {//from   w w  w .  jav  a  2 s  . c om
        XYSeries series = new XYSeries("Delay");
        for (Point point : vector)
            series.add(point.date / 1000, 1 / point.frequency);
        XYDataset xyDataset = new XYSeriesCollection(series);
        JFreeChart chart = ChartFactory.createXYLineChart(null, "date (s)", "delay (s)", xyDataset,
                PlotOrientation.VERTICAL, false, true, false);
        ChartPanel panel = new ChartPanel(chart);
        panel.setPreferredSize(jPanelGraph.getSize());
        this.jPanelGraph.add(panel);
        this.jPanelGraph.validate();
    } else // frequency graph
    {
        XYSeries series = new XYSeries("Frequency");
        for (Point point : vector)
            series.add(point.date / 1000, point.frequency);
        XYDataset xyDataset = new XYSeriesCollection(series);
        JFreeChart chart = ChartFactory.createXYLineChart(null, "date (s)", "frequency (hz)", xyDataset,
                PlotOrientation.VERTICAL, false, true, false);
        chart.setPadding(new RectangleInsets(0, 0, 0, 0));
        ChartPanel panel = new ChartPanel(chart);
        panel.setPreferredSize(jPanelGraph.getSize());
        this.jPanelGraph.add(panel);
        this.jPanelGraph.validate();
    }
}

From source file:guineu.modules.filter.Alignment.RANSAC.AlignmentRansacPlot.java

public AlignmentRansacPlot() {
    super(null, true);

    dataset = new XYSeriesCollection();
    chart = ChartFactory.createXYLineChart("", null, null, dataset, PlotOrientation.VERTICAL, true, true,
            false);//from w ww .j  a v a  2  s.  co m

    chart.setBackgroundPaint(Color.white);
    setChart(chart);

    // title
    chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    // legend constructed by ChartFactory
    legend = chart.getLegend();
    legend.setItemFont(legendFont);
    //     legend.setFrame(BlockBorder.NONE);

    // set the plot properties
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // set grid properties
    plot.setDomainGridlinePaint(gridColor);
    plot.setRangeGridlinePaint(gridColor);

    // set crosshair (selection) properties

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairPaint(crossHairColor);
    plot.setRangeCrosshairPaint(crossHairColor);
    plot.setDomainCrosshairStroke(crossHairStroke);
    plot.setRangeCrosshairStroke(crossHairStroke);

    // set default renderer properties
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseLinesVisible(false);
    renderer.setBaseShapesVisible(true);
    renderer.setSeriesShape(0, dataPointsShape);
    renderer.setSeriesShape(1, dataPointsShape);
    renderer.setSeriesLinesVisible(2, true);
    renderer.setSeriesShapesVisible(2, false);
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GRAY);
    renderer.setSeriesPaint(2, Color.BLUE);
    renderer.setBaseItemLabelPaint(labelsColor);

    plot.setRenderer(renderer);

}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart(null, "Age in Months", "Weight (kg)", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    TextTitle texttitle = new TextTitle("Growth Charts: United States", new Font("SansSerif", 1, 14));
    TextTitle texttitle1 = new TextTitle("Weight-for-age percentiles: boys, birth to 36 months",
            new Font("SansSerif", 0, 11));
    jfreechart.addSubtitle(texttitle);/*  w  w w  .  j  a v  a 2s .  co  m*/
    jfreechart.addSubtitle(texttitle1);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setUpperMargin(0.12D);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setAutoRangeIncludesZero(false);
    XYTextAnnotation xytextannotation = null;
    Font font = new Font("SansSerif", 0, 9);
    xytextannotation = new XYTextAnnotation("3rd", 36.5D, 11.76D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("5th", 36.5D, 12.039999999999999D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("10th", 36.5D, 12.493D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("25th", 36.5D, 13.313000000000001D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("50th", 36.5D, 14.33D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("75th", 36.5D, 15.478D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("90th", 36.5D, 16.641999999999999D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("95th", 36.5D, 17.408000000000001D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("97th", 36.5D, 17.936D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    return jfreechart;
}

From source file:br.prof.salesfilho.oci.image.GraphicBuilder.java

public void createChart() {
    chart = ChartFactory.createXYLineChart(this.title, this.xLabel, this.yLabel, this.collectionDataset,
            PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    List<XYSeries> listSeries = collectionDataset.getSeries();
    for (int i = 0; i < listSeries.size(); i++) {
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesShapesVisible(i, true);
        renderer.setSeriesShapesFilled(i, false);
    }//from   w w  w . j av  a  2s.  com

    plot.setRenderer(renderer);
    plot.setRangePannable(true);
    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    chartPanel.setChart(chart);

}

From source file:org.nees.rpi.vis.ui.XYChartPanelProxy.java

public XYChartPanelProxy(int width, int height) {
    selectionGroup = new SelectionGroup();
    selectionGroup.setSelection(true);/*from   www.jav a 2 s  .  c  om*/

    dataSet = new XYSeriesCollection();
    chart = ChartFactory.createXYLineChart(null, domainAxisLabel, rangeAxisLabel, dataSet,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.WHITE);
    chart.getLegend().setPosition(RectangleEdge.RIGHT);

    chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(width, height));
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setHorizontalAxisTrace(true);
    chartPanel.setVerticalAxisTrace(true);

    toolPanel = new JPanel();
    toolPanel.setOpaque(false);
    toolPanel.setLayout(new BoxLayout(toolPanel, BoxLayout.Y_AXIS));
    toolPanel.setBorder(BorderFactory.createTitledBorder("Plot Control"));
    toolPanel.setPreferredSize(new Dimension(155, 100));

    chartAreaPanel = new JPanel();
    chartAreaPanel.setOpaque(true);
    chartAreaPanel.setBackground(Color.white);
    chartAreaPanel.setLayout(new BorderLayout());
    chartAreaPanel.add(chartPanel, BorderLayout.CENTER);
    chartAreaPanel.add(toolPanel, BorderLayout.WEST);

    initClearSelectionButton(toolPanel);
    initResetPlotButton(toolPanel);
    initSaveToImageButton(toolPanel);
    initShowAsProfilePlotButton(toolPanel);
}