Example usage for org.jfree.chart.plot XYPlot XYPlot

List of usage examples for org.jfree.chart.plot XYPlot XYPlot

Introduction

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

Prototype

public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer) 

Source Link

Document

Creates a new plot with the specified dataset, axes and renderer.

Usage

From source file:com.jbombardier.console.charts.XYTimeChartPanel.java

public XYTimeChartPanel() {

    DateAxis numberaxis = new DateAxis("Time");

    yAxis = new NumberAxis("Count");
    yAxis.setAutoRangeIncludesZero(true);

    XYSplineRenderer renderer = new XYSplineRenderer();
    // XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    xyplot = new XYPlot(xyseriescollection, numberaxis, yAxis, renderer);
    xyplot.setBackgroundPaint(Color.white);
    xyplot.setDomainGridlinePaint(Color.lightGray);
    xyplot.setRangeGridlinePaint(Color.lightGray);

    // xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));

    // XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)
    // xyplot.getRenderer();
    // xylineandshaperenderer.setBaseShapesVisible(false);
    // xylineandshaperenderer.setBaseShapesFilled(false);

    chart = new JFreeChart("Running threads", JFreeChart.DEFAULT_TITLE_FONT, xyplot, true);

    /*/*from   w ww  .  j  a va2  s. c o m*/
     * ValueMarker valuemarker1 = new ValueMarker(175D);
     * valuemarker1.setLabelOffsetType(LengthAdjustmentType.EXPAND);
     * valuemarker1.setPaint(Color.red); valuemarker1.setLabel("Target Price");
     * valuemarker1.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
     * valuemarker1.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
     * xyplot.addRangeMarker(valuemarker1);
     */

    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);

    // ChartUtilities.applyCurrentTheme(chart);
    setLayout(new BorderLayout());
    jFreeChartPanel = new ChartPanel(chart);
    jFreeChartPanel.setMinimumDrawHeight(0);
    jFreeChartPanel.setMinimumDrawWidth(0);
    jFreeChartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    jFreeChartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);

    add(jFreeChartPanel, BorderLayout.CENTER);

    JPanel controls = new JPanel(new MigLayout("gap 0, ins 0", "[grow,center,fill]", "[grow,center]"));
    final JCheckBox checkbox = new JCheckBox("Auto-scale");
    checkbox.setSelected(true);
    checkbox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            toggleAutoscroll(checkbox.isSelected());
        }
    });
    checkbox.setHorizontalAlignment(SwingConstants.RIGHT);
    controls.add(checkbox, "cell 0 0,alignx center");
    add(controls, BorderLayout.SOUTH);
}

From source file:org.codehaus.mojo.chronos.chart.ChartUtil.java

static XYPlot newPlot(XYDataset dataset, String label, boolean forceIncludeZero) {
    StandardXYItemRenderer standardxyitemrenderer = new StandardXYItemRenderer();
    NumberAxis numberaxis = new NumberAxis(label);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setAutoRangeIncludesZero(forceIncludeZero);
    return new XYPlot(dataset, null, numberaxis, standardxyitemrenderer);
}

From source file:com.sixrr.metrics.ui.charts.DistributionDialog.java

private JFreeChart createChart(XYDataset dataset) {
    final String title = getTitle();

    final NumberAxis xAxis = new NumberAxis(metricName);
    xAxis.setAutoRangeIncludesZero(false);
    if (metricType == MetricType.Ratio || metricType == MetricType.RecursiveRatio) {
        xAxis.setNumberFormatOverride(new PercentFormatter());
    }// w  ww  . jav  a  2s . c  o  m
    final NumberAxis yAxis = new NumberAxis("%");
    final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES);
    final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    return new JFreeChart(title, JFreeChartConstants.DEFAULT_TITLE_FONT, plot, true);
}

From source file:net.sf.maltcms.common.charts.api.XYChartBuilder.java

/**
 *
 *//*from   w  w w. jav a 2s .c om*/
public XYChartBuilder() {
    plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
    chart = new JFreeChart(plot);
    renderingHints = new RenderingHints(null);
    renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
    renderingHints.put(RenderingHints.KEY_TEXT_LCD_CONTRAST, 100);
    renderingHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    renderingHints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    renderingHints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
    renderingHints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    renderingHints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    renderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    renderingHints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    renderingHints.put(RenderingHints.KEY_ALPHA_INTERPOLATION,
            RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
}

From source file:com.att.aro.ui.view.diagnostictab.CreateBarPlot.java

public XYPlot drawStandardXYPlot(Shape shape, Color color, int minSignal, int maxSignal) {
    // Set up renderer
    StandardXYItemRenderer batteryRenderer = new StandardXYItemRenderer(
            StandardXYItemRenderer.SHAPES_AND_LINES);
    batteryRenderer.setAutoPopulateSeriesShape(false);
    batteryRenderer.setBaseShape(shape);
    batteryRenderer.setSeriesPaint(0, color);

    // Normalize the throughput axis so that it represents max value
    NumberAxis axis = new NumberAxis();
    axis.setVisible(false);/*from  www.j ava2 s.co  m*/
    axis.setAutoRange(false);
    axis.setRange(minSignal, maxSignal);

    // Create plot
    XYPlot barPlot = new XYPlot(null, null, axis, batteryRenderer);
    barPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    barPlot.getRangeAxis().setVisible(false);

    return barPlot;
}

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

/**
 * Creates a combined XYPlot chart./* w  ww .j  a  va 2 s.  c om*/
 *
 * @return the combined chart.
 */
private JFreeChart createCombinedChart() {

    // create subplot 1...
    final IntervalXYDataset data1 = createDataset1();
    final XYItemRenderer renderer1 = new XYBarRenderer(0.20);
    renderer1.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.0")));
    final XYPlot subplot1 = new XYPlot(data1, new DateAxis("Date"), null, renderer1);

    // create subplot 2...
    final XYDataset data2 = createDataset2();
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.0")));
    final XYPlot subplot2 = new XYPlot(data2, new DateAxis("Date"), null, renderer2);

    // create a parent plot...
    final CombinedRangeXYPlot plot = new CombinedRangeXYPlot(new NumberAxis("Value"));

    // add the subplots...
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);

    // return a new chart containing the overlaid plot...
    return new JFreeChart("Combined (Range) XY Plot", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

}

From source file:edu.caltechUcla.sselCassel.projects.jMarkets.shared.interfaces.PriceChart.java

public JPanel getChartPanel() {
    XYSeriesCollection collection = new XYSeriesCollection();

    Enumeration en = lines.elements();
    while (en.hasMoreElements()) {
        XYSeries series = (XYSeries) en.nextElement();
        collection.addSeries(series);//  ww  w .j  a v  a2  s. com
    }

    NumberAxis yAxis = new NumberAxis("Price");
    NumberAxis xAxis = new NumberAxis("Time");

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    XYPlot plot = new XYPlot(collection, xAxis, yAxis, renderer);

    JFreeChart chart = new JFreeChart("Price Chart", new Font("Arial", 0, 12), plot, true);
    ChartPanel chartPanel = new ChartPanel(chart, false, false, false, false, false);

    return chartPanel;
}

From source file:com.wattzap.view.graphs.MMPGraph.java

public MMPGraph(XYSeries series) {
    super();//from  w ww .  jav a 2s .co m

    NumberAxis yAxis = new NumberAxis(userPrefs.messages.getString("poWtt"));
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    double maxY = series.getMaxY();
    yAxis.setRange(0, maxY + 20);
    yAxis.setTickLabelPaint(Color.white);
    yAxis.setLabelPaint(Color.white);

    LogAxis xAxis = new LogAxis(userPrefs.messages.getString("time"));
    xAxis.setTickLabelPaint(Color.white);
    xAxis.setBase(4);
    xAxis.setAutoRange(false);

    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    xAxis.setRange(1, series.getMaxX() + 500);
    xAxis.setNumberFormatOverride(new NumberFormat() {

        @Override
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {

            long millis = (long) number * 1000;

            if (millis >= 60000) {
                return new StringBuffer(String.format("%d m %d s",
                        TimeUnit.MILLISECONDS.toMinutes((long) millis),
                        TimeUnit.MILLISECONDS.toSeconds((long) millis)
                                - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis))));
            } else {
                return new StringBuffer(String.format("%d s",

                        TimeUnit.MILLISECONDS.toSeconds((long) millis)
                                - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis))));
            }
        }

        @Override
        public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
            return new StringBuffer(String.format("%s", number));
        }

        @Override
        public Number parse(String source, ParsePosition parsePosition) {
            return null;
        }
    });

    XYPlot plot = new XYPlot(new XYSeriesCollection(series), xAxis, yAxis,
            new XYLineAndShapeRenderer(true, false));

    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    chart.setBackgroundPaint(Color.gray);
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.darkGray);
    /*plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);*/

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickLabelPaint(Color.white);
    domainAxis.setLabelPaint(Color.white);

    chartPanel = new ChartPanel(chart);
    chartPanel.setSize(100, 800);
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setBackground(Color.gray);

    setLayout(new BorderLayout());
    add(chartPanel, BorderLayout.CENTER);
    setBackground(Color.black);
    chartPanel.revalidate();
    setVisible(true);
}

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

/**
 * Creates a combined XYPlot chart.//  w  ww . ja  v  a 2 s.c  o m
 *
 * @return the combined chart.
 */
private JFreeChart createCombinedChart() {

    // create a default chart based on some sample data...
    final TimeSeriesCollection dataset0 = new TimeSeriesCollection();
    final TimeSeries eur = DemoDatasetFactory.createEURTimeSeries();
    dataset0.addSeries(eur);

    final TimeSeriesCollection dataset1 = new TimeSeriesCollection();
    final TimeSeries mav = MovingAverage.createMovingAverage(eur, "EUR/GBP (30 Day MA)", 30, 30);
    dataset1.addSeries(eur);
    dataset1.addSeries(mav);

    final TimeSeriesCollection dataset2 = new TimeSeriesCollection();
    dataset2.addSeries(eur);

    JFreeChart chart = null;

    // make a common vertical axis for all the sub-plots
    final NumberAxis valueAxis = new NumberAxis("Value");
    valueAxis.setAutoRangeIncludesZero(false); // override default

    // make a horizontally combined plot
    final CombinedRangeXYPlot parent = new CombinedRangeXYPlot(valueAxis);

    // add subplot 1...
    final XYPlot subplot1 = new XYPlot(dataset0, new DateAxis("Date 1"), null, new StandardXYItemRenderer());
    parent.add(subplot1, 1);

    // add subplot 2...
    final XYPlot subplot2 = new XYPlot(dataset1, new DateAxis("Date 2"), null, new StandardXYItemRenderer());
    parent.add(subplot2, 1);

    // add subplot 3...
    final XYPlot subplot3 = new XYPlot(dataset2, new DateAxis("Date 3"), null, new XYBarRenderer(0.20));
    parent.add(subplot3, 1);

    // now make the top level JFreeChart
    chart = new JFreeChart("Demo Chart", JFreeChart.DEFAULT_TITLE_FONT, parent, true);

    // then customise it a little...
    final TextTitle subtitle = new TextTitle("This is a subtitle", new Font("SansSerif", Font.BOLD, 12));
    chart.addSubtitle(subtitle);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));
    return chart;

}

From source file:org.mwc.debrief.multipath2.MultiPathView.java

private void createPlot(final Composite ui) { // create a date-formatting axis
    final DateAxis dateAxis = new RelativeDateAxis();
    dateAxis.setStandardTickUnits(DateAxisEditor.createStandardDateTickUnitsAsTickUnits());

    final NumberAxis valAxis = new NumberAxis("Delay (Secs)");
    final DefaultXYItemRenderer theRenderer = new DefaultXYItemRenderer();
    theRenderer.setBaseShapesVisible(false);

    _thePlot = new XYPlot(null, dateAxis, valAxis, theRenderer);
    final JFreeChart _plotArea = new JFreeChart(_thePlot);

    final ChartComposite _plotControl = new ChartComposite(ui, SWT.NONE, null, true) {
        @Override/*  w w  w  .  j a v  a2  s  .c  om*/
        public void mouseUp(MouseEvent event) {
            super.mouseUp(event);
            JFreeChart c = getChart();
            if (c != null) {
                c.setNotify(true); // force redraw
            }
        }
    };
    _plotControl.setChart(_plotArea);
}