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:XYPlotter.java

/**
 * Creates a chart and a plotpanel and add it to the mainwindow.
 *///www .  j a  v  a2 s  . c  om
private void createChart() {

    getContentPane().removeAll();

    xyDataset = createDataset("");

    // create the chart...
    chart = ChartFactory.createXYLineChart("", // chart title   "Line Chart Demo 6"
            "x", // x axis label
            "f(x)", // y axis label
            xyDataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    renderer.setSeriesShapesVisible(0, false); // a thin line will be painted for series1
    renderer.setSeriesLinesVisible(1, false); // points will be painted for series2

    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    chartPanel = new ChartPanel(chart);
    getContentPane().add(chartPanel);
}

From source file:sanger.team16.gui.genevar.eqtl.snp.RegionalLinePlot.java

private JFreeChart createChart(String chromosome, int position, int distance, double threshold,
        XYDataset dataset) {// w ww  .  j  a v  a2s. co m
    JFreeChart chart = ChartFactory.createXYLineChart(null, "Position on chromosome " + chromosome + " (bp)",
            "-log10(P)", dataset, PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.lightGray);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setShapesVisible(true);
    //renderer.setShapesFilled(false);   //CHANGED 12/12/11
    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    /*       
           XYItemRenderer renderer = plot.getRenderer();  
           int size = dataset.getSeriesCount();
           for (int i=0 ; i<size ; i++) {
    //renderer.setSeriesPaint(i, new Color(255, 0, 0));
    renderer.setSeriesShape(i, ShapeUtilities.createDiamond((float) 3));
    renderer.setBaseSeriesVisibleInLegend(false);
           }
          */
    ValueMarker upperMarker = new ValueMarker(-Math.log10(threshold));
    upperMarker.setPaint(Color.gray);
    float[] f = { 4, 3, 4, 3 };
    upperMarker.setStroke(new BasicStroke(1.0f, 1, 1, 0, f, 1.0f));
    plot.addRangeMarker(upperMarker);

    ValueMarker marker = new ValueMarker(0.0);
    marker.setPaint(Color.lightGray);
    plot.addRangeMarker(marker);

    XYSeries series = new XYSeries("Range");
    series.add(position - distance, -0.05);
    series.add(position + distance, -0.05);
    ((XYSeriesCollection) dataset).addSeries(series);
    renderer.setSeriesVisible(dataset.getSeriesCount() - 1, false, false);

    return chart;
}

From source file:playground.anhorni.crossborder.verification.TGZMCompare.java

public JFreeChart createChart(String actType) {

    XYSeriesCollection dataset0 = new XYSeriesCollection();
    XYSeries series0 = new XYSeries(actType + " Trips MATSim");
    XYSeries series1 = new XYSeries(actType + " Trips TGZM");

    for (int i = 0; i < 24; i++) {
        double realVal = this.aggregatedVolumePerHour[i];
        int calcVal = this.xTripsPerHour[i];
        series0.add(i, calcVal);/*from  w ww  . java 2s .  c  o m*/
        series1.add(i, realVal);
    }
    dataset0.addSeries(series0);
    dataset0.addSeries(series1);

    String title = "Compare TGZM and MATSim volumes per hour";
    this.chart = ChartFactory.createXYLineChart(title, "hour", // x axis label
            "Trips", // y axis label
            dataset0, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    XYPlot plot = this.chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLinesVisible(true);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0));
    renderer.setSeriesPaint(1, Color.black);
    renderer.setSeriesShape(1, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0));

    plot.setRenderer(0, renderer);

    return this.chart;
}

From source file:org.ujmp.jfreechart.MatrixChartPanel.java

public synchronized void redraw() {
    Dataset dataset = null;//from   w w w .  j a v a  2s.c  o  m
    dataset = new XYSeriesCollectionWrapper(getMatrix());
    // dataset = new CategoryDatasetWrapper(getMatrix());

    String title = getMatrix().getLabel();
    String xLabel = StringUtil.format(getMatrix().getMatrix().getDimensionLabel(Matrix.ROW));
    String yLabel = null;

    // setChart(ChartFactory.createLineChart(title, xLabel, yLabel,
    // (CategoryDataset) dataset, PlotOrientation.VERTICAL, true,
    // true, false));
    setChart(ChartFactory.createXYLineChart(title, xLabel, yLabel, (XYDataset) dataset,
            PlotOrientation.VERTICAL, true, true, false));

    XYPlot plot = getChart().getXYPlot();

    if (getConfig().isLogScaleDomain()) {
        try {
            NumberAxis axis = new LogarithmicAxis(null);
            plot.setDomainAxis(axis);
        } catch (Exception e) {
            NumberAxis axis = new NumberAxis();
            plot.setDomainAxis(axis);
        }
    } else {
        NumberAxis axis = new NumberAxis();
        plot.setDomainAxis(axis);
    }

    if (getConfig().isLogScaleRange()) {
        try {
            NumberAxis axis = new LogarithmicAxis(null);
            plot.setRangeAxis(axis);
        } catch (Exception e) {
            NumberAxis axis = new NumberAxis();
            plot.setRangeAxis(axis);
        }
    } else {
        NumberAxis axis = new NumberAxis();
        plot.setRangeAxis(axis);
    }

    getChart().setTitle((String) null);

    getChart().setBackgroundPaint(Color.WHITE);

    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    renderer.setBaseShapesVisible(false);
    renderer.setDrawSeriesLineAsPath(true);
    for (int i = 0; i < getMatrix().getColumnCount(); i++) {
        renderer.setSeriesStroke(i, new BasicStroke(3));
        plot.setRenderer(i, renderer);
    }

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);

    plot.getRangeAxis().setAutoRange(true);
    plot.getDomainAxis().setAutoRange(true);
    plot.getDomainAxis().setUpperMargin(0);

    setMouseZoomable(false);
}

From source file:physical_network.OscilloscopePanel.java

public OscilloscopePanel() {

    super("Oscilloscope");

    // Set initial (time, voltage) datapoint of (0.0, 0.0).
    voltages.add(0.0, 0.0);/*w  ww  .  j ava  2s.c  o  m*/

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(voltages);

    JFreeChart chart = ChartFactory.createXYLineChart("Oscilloscope", "Time (seconds)", "Voltage", dataset,
            PlotOrientation.VERTICAL, true, false, false);

    XYPlot plot = (XYPlot) chart.getPlot();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);

    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setRange(0.0, 10.0);
    domain.setTickUnit(new NumberTickUnit(1.0));
    domain.setVerticalTickLabels(true);

    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setRange(-5.0, 5.0);
    range.setTickUnit(new NumberTickUnit(1.0));

    plot.setRenderer(renderer);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));

    setContentPane(chartPanel);
}

From source file:simphy.XYChart.java

public XYChart(Circle c) {
    this.c = c;//from w  w  w  .ja  va 2 s.  co  m
    // Create a simple XY chart
    type = "circle";
    series = new XYSeries("VT Plot");
    dataset = new XYSeriesCollection();
    dataset.addSeries(series);
    // Generate the graph
    chart = ChartFactory.createXYLineChart("Velocity-Time Graph", // Title
            "time(s)", // x-axis Label
            "velocity(m/s)", // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );
    this.setTitle(c.getID());
    this.setBounds(950, 0, 400, 700);
    panel = new ChartPanel(chart, false);
    this.add(panel, BorderLayout.CENTER);
    this.setAlwaysOnTop(true);
    this.addWindowListener(this);
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    this.pack();

    SwingUtilities.invokeLater(() -> {
        XYChart.this.setVisible(true);
    });

}

From source file:com.netblizzard.jfreechart.MouseZoomDemo.java

/**
 * A demonstration of mouse zooming./*ww  w  . j  a  v a2s.c om*/
 *
 * @param title  the frame title.
 */
public MouseZoomDemo(String title) {

    super(title);
    SampleXYDataset data = new SampleXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Mouse Zoom Demo", "X", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);

    this.chartPanel = new ChartPanel(chart);
    this.chartPanel.setHorizontalAxisTrace(false);
    //        this.chartPanel.setVerticalTraceLine(false);
    this.chartPanel.setHorizontalAxisTrace(false);
    this.chartPanel.setVerticalAxisTrace(false);
    this.chartPanel.setFillZoomRectangle(true);
    this.chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

    JPanel main = new JPanel(new BorderLayout());
    JPanel checkpanel = new JPanel();
    this.xzoom = new JCheckBox("Horizontal Mouse Zooming");
    this.xzoom.setSelected(false);
    this.yzoom = new JCheckBox("Vertical Mouse Zooming");
    this.yzoom.setSelected(false);
    CheckListener clisten = new CheckListener();
    this.xzoom.addItemListener(clisten);
    this.yzoom.addItemListener(clisten);
    checkpanel.add(this.xzoom);
    checkpanel.add(this.yzoom);
    main.add(checkpanel, BorderLayout.SOUTH);
    main.add(this.chartPanel);
    setContentPane(main);

}

From source file:org.ow2.clif.jenkins.chart.CallChart.java

@Override
protected JFreeChart createChart() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(this.eventSerie);

    JFreeChart chart;//from   ww  w .  ja v  a  2 s  . c o  m
    if (this.scatterPlot) {
        chart = ChartFactory.createScatterPlot(getBasicTitle(),
                // chart title
                Messages.CallChart_Time(), // x axis label
                Messages.CallChart_ResponseTime(), // y axis label
                dataset, // data
                PlotOrientation.VERTICAL, true, // include legend
                true, // tooltips
                false // urls
        );
    } else {
        chart = ChartFactory.createXYLineChart(getBasicTitle(),
                // chart title
                Messages.CallChart_Time(), // x axis label
                this.chartId.getEvent(), // y axis label
                dataset, // data
                PlotOrientation.VERTICAL, false, // include legend
                true, // tooltips
                false // urls
        );
    }

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

    Shape cross = ShapeUtilities.createDiamond(3);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShape(cross);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShape(0, cross);
    plot.setRenderer(renderer);

    // Force the 0 on vertical axis
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(true);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Force the 0 on horizontal axis
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(true);
    return chart;
}

From source file:org.matsim.core.utils.charts.XYLineChart.java

private JFreeChart createChart(final String title, final String categoryAxisLabel, final String valueAxisLabel,
        final XYSeriesCollection dataset) {
    JFreeChart c = ChartFactory.createXYLineChart(title, categoryAxisLabel, valueAxisLabel, dataset,
            PlotOrientation.VERTICAL, true, // legend?
            false, // tooltips?
            false // URLs?
    );//from  www. j ava2 s.co  m
    if (this.isLogarithmicAxis) {
        XYPlot p = (XYPlot) c.getPlot();
        LogarithmicAxis axis_x = new LogarithmicAxis(this.xAxisLabel);
        LogarithmicAxis axis_y = new LogarithmicAxis(this.yAxisLabel);
        axis_x.setAllowNegativesFlag(false);
        axis_y.setAllowNegativesFlag(false);
        p.setDomainAxis(axis_x);
        p.setRangeAxis(axis_y);
    }
    return c;
}

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

/**
 * A demonstration application showing an {@link XYSeries} where all the y-values are the same.
 *
 * @param title  the frame title.//from  www .j a  v  a2  s.  co m
 */
public XYSeriesDemo2(final String title) {

    super(title);
    final XYSeries series = new XYSeries("Flat Data");
    series.add(1.0, 100.0);
    series.add(5.0, 100.0);
    series.add(4.0, 100.0);
    series.add(12.5, 100.0);
    series.add(17.3, 100.0);
    series.add(21.2, 100.0);
    series.add(21.9, 100.0);
    series.add(25.6, 100.0);
    series.add(30.0, 100.0);
    final XYSeriesCollection data = new XYSeriesCollection(series);
    final JFreeChart chart = ChartFactory.createXYLineChart("XY Series Demo 2", "X", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);

    final XYPlot plot = (XYPlot) chart.getPlot();
    final NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRangeIncludesZero(false);
    axis.setAutoRangeMinimumSize(1.0);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}