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:org.jfree.chart.demo.StackedXYBarChartDemo2.java

private static JFreeChart createChart(TableXYDataset tablexydataset) {
    DateAxis dateaxis = new DateAxis("Date");
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    dateaxis.setLowerMargin(0.01D);//w w  w.ja  v a2s  .  c  o m
    dateaxis.setUpperMargin(0.01D);
    NumberAxis numberaxis = new NumberAxis("Count");
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setUpperMargin(0.10000000000000001D);
    StackedXYBarRenderer stackedxybarrenderer = new StackedXYBarRenderer(0.14999999999999999D);
    stackedxybarrenderer.setDrawBarOutline(false);
    stackedxybarrenderer.setBaseItemLabelsVisible(true);
    stackedxybarrenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    stackedxybarrenderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER));
    stackedxybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} : {1} = {2}",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0")));
    XYPlot xyplot = new XYPlot(tablexydataset, dateaxis, numberaxis, stackedxybarrenderer);
    JFreeChart jfreechart = new JFreeChart("Holes-In-One / Double Eagles", xyplot);
    jfreechart.removeLegend();
    jfreechart.addSubtitle(new TextTitle("PGA Tour, 1983 to 2003"));
    TextTitle texttitle = new TextTitle(
            "http://www.golfdigest.com/majors/masters/index.ssf?/majors/masters/gw20040402albatross.html",
            new Font("Dialog", 0, 8));
    jfreechart.addSubtitle(texttitle);
    jfreechart.setTextAntiAlias(RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
    LegendTitle legendtitle = new LegendTitle(xyplot);
    legendtitle.setBackgroundPaint(Color.white);
    legendtitle.setFrame(new BlockBorder());
    legendtitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(legendtitle);
    return jfreechart;
}

From source file:org.esa.smos.gui.gridpoint.GridPointBtDataFlagmatrixTopComponent.java

@Override
protected JComponent createGridPointComponent() {
    dataset = new DefaultXYZDataset();

    final NumberAxis xAxis = new NumberAxis("Record #");
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setLowerMargin(0.0);/*from www. j a v a  2  s .  c o  m*/
    xAxis.setUpperMargin(0.0);

    final List<FlagDescriptor> flagDescriptorList = Dddb.getInstance()
            .getFlagDescriptors(DEFAULT_FLAG_DESCRIPTOR_IDENTIFIER).asList();
    flagDescriptors = flagDescriptorList.toArray(new FlagDescriptor[flagDescriptorList.size()]);
    final String[] flagNames = createFlagNames(flagDescriptors);
    final NumberAxis yAxis = createRangeAxis(flagNames);

    final LookupPaintScale paintScale = new LookupPaintScale(0.0, 4.0, Color.WHITE);
    paintScale.add(0.0, Color.BLACK);
    paintScale.add(1.0, Color.RED);
    paintScale.add(2.0, Color.GREEN);
    paintScale.add(3.0, Color.BLUE);
    paintScale.add(4.0, Color.YELLOW);

    renderer = new XYBlockRenderer();
    renderer.setPaintScale(paintScale);
    renderer.setBaseToolTipGenerator(new FlagToolTipGenerator(flagNames));

    plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);
    plot.setForegroundAlpha(0.5f);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    plot.setNoDataMessage("No data");

    chart = new JFreeChart(null, plot);
    chart.removeLegend();
    chartPanel = new ChartPanel(chart);

    return chartPanel;
}

From source file:org.ietr.preesm.mapper.ui.stats.PerformancePlotter.java

/**
 * Creates a chart in order to plot the speed-ups.
 * //from w  ww.ja v a2s .  co  m
 * @return A chart.
 */
private JFreeChart createChart(String title) {

    // Creating display domain
    NumberAxis horizontalAxis = new NumberAxis("Number of operators");
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(horizontalAxis);

    // Creating the best speedups subplot
    this.speedups = new DefaultXYDataset();

    final NumberAxis xAxis = new NumberAxis("speedups");

    xAxis.setAutoRangeIncludesZero(false);

    XYSplineRenderer renderer = new XYSplineRenderer();
    final XYPlot subplot = new XYPlot(this.speedups, null, xAxis, renderer);

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

    plot.setForegroundAlpha(0.5f);

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

    chart.setBorderPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);

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

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

    return chart;

}

From source file:LoggerGUI.DataLogger.java

public DataLogger(String title) {
    super(title);
    initialize();//from w  w w.  j a v a  2  s  . c  o  m

    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:com.idealista.solrmeter.view.statistic.OperationTimeLineChartPanel.java

private Component createChartPanel() {
    NumberAxis xaxis = new NumberAxis(I18n.get("statistic.operationTimeLineChartPanel.executionInstant"));
    NumberAxis yaxis = new NumberAxis(I18n.get("statistic.operationTimeLineChartPanel.qTime"));

    XYPlot plot = new XYPlot(xyDataset, xaxis, yaxis, new XYLineAndShapeRenderer(true, true));

    JFreeChart chart = new JFreeChart(I18n.get("statistic.operationTimeLineChartPanel.title"), null, plot,
            true);/*from  w w  w. j  a v  a  2 s.  c o m*/
    chart.getLegend().setPosition(RectangleEdge.RIGHT);

    ChartPanel chartPanel = new ChartPanel(chart);

    chartPanel.setBorder(CHART_BORDER);
    chartPanel.setMinimumDrawHeight(0);
    chartPanel.setMinimumDrawWidth(0);
    chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);

    return chartPanel;
}

From source file:com.unicornlabs.kabouter.reporting.PowerReport.java

public static void GeneratePowerReport(Date startDate, Date endDate) {
    try {//from w  w w  .  j a  va  2  s . c  o m
        Historian theHistorian = (Historian) BusinessObjectManager.getBusinessObject(Historian.class.getName());
        ArrayList<String> powerLogDeviceIds = theHistorian.getPowerLogDeviceIds();

        Document document = new Document(PageSize.A4, 50, 50, 50, 50);

        File outputFile = new File("PowerReport.pdf");
        outputFile.createNewFile();

        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile));
        document.open();

        document.add(new Paragraph("Power Report for " + startDate.toString() + " to " + endDate.toString()));

        document.newPage();

        DecimalFormat df = new DecimalFormat("#.###");

        for (String deviceId : powerLogDeviceIds) {
            ArrayList<Powerlog> powerlogs = theHistorian.getPowerlogs(deviceId, startDate, endDate);
            double total = 0;
            double max = 0;
            Date maxTime = startDate;
            double average = 0;
            XYSeries series = new XYSeries(deviceId);
            XYDataset dataset = new XYSeriesCollection(series);

            for (Powerlog log : powerlogs) {
                total += log.getPower();
                if (log.getPower() > max) {
                    max = log.getPower();
                    maxTime = log.getId().getLogtime();
                }
                series.add(log.getId().getLogtime().getTime(), log.getPower());
            }

            average = total / powerlogs.size();

            document.add(new Paragraph("\nDevice: " + deviceId));
            document.add(new Paragraph("Average Power Usage: " + df.format(average)));
            document.add(new Paragraph("Maximum Power Usage: " + df.format(max) + " at " + maxTime.toString()));
            document.add(new Paragraph("Total Power Usage: " + df.format(total)));
            //Create a custom date axis to display dates on the X axis
            DateAxis dateAxis = new DateAxis("Date");
            //Make the labels vertical
            dateAxis.setVerticalTickLabels(true);

            //Create the power axis
            NumberAxis powerAxis = new NumberAxis("Power");

            //Set both axes to auto range for their values
            powerAxis.setAutoRange(true);
            dateAxis.setAutoRange(true);

            //Create the tooltip generator
            StandardXYToolTipGenerator ttg = new StandardXYToolTipGenerator("{0}: {2}",
                    new SimpleDateFormat("yyyy/MM/dd HH:mm"), NumberFormat.getInstance());

            //Set the renderer
            StandardXYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES, ttg,
                    null);

            //Create the plot
            XYPlot plot = new XYPlot(dataset, dateAxis, powerAxis, renderer);

            //Create the chart
            JFreeChart myChart = new JFreeChart(deviceId, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

            PdfContentByte pcb = writer.getDirectContent();
            PdfTemplate tp = pcb.createTemplate(480, 360);
            Graphics2D g2d = tp.createGraphics(480, 360, new DefaultFontMapper());
            Rectangle2D r2d = new Rectangle2D.Double(0, 0, 480, 360);
            myChart.draw(g2d, r2d);
            g2d.dispose();
            pcb.addTemplate(tp, 0, 0);

            document.newPage();
        }

        document.close();

        JOptionPane.showMessageDialog(null, "Report Generated.");

        Desktop.getDesktop().open(outputFile);
    } catch (FileNotFoundException fnfe) {
        JOptionPane.showMessageDialog(null,
                "Unable To Open File For Writing, Make Sure It Is Not Currently Open");
    } catch (IOException ex) {
        Logger.getLogger(PowerReport.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(PowerReport.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.mwc.asset.netasset2.sensor2.VSensor.java

/**
 * Create the composite.//from  w  w w  .j  ava 2 s  .c  om
 * 
 * @param parent
 * @param style
 */
public VSensor(final Composite parent, final int style) {
    super(parent, style);
    setLayout(new BorderLayout(0, 0));

    final ToolBar toolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT);
    toolBar.setLayoutData(BorderLayout.NORTH);

    // ToolItem testBtn = new ToolItem(toolBar, SWT.NONE);
    // testBtn.setText("Test 1");
    // testBtn.addSelectionListener(new SelectionAdapter()
    // {
    //
    // @Override
    // public void widgetSelected(SelectionEvent e)
    // {
    // doTest();
    // }
    // });

    final ToolItem tltmDropdownItem = new ToolItem(toolBar, SWT.DROP_DOWN);
    tltmDropdownItem.setText("Visible period");
    final DropdownSelectionListener drops = new DropdownSelectionListener(tltmDropdownItem);
    drops.add("5 Mins", 5 * 60);
    drops.add("15 Mins", 15 * 60);
    drops.add("60 Mins", 60 * 60);
    drops.add("All data", 0);
    tltmDropdownItem.addSelectionListener(drops);

    final Composite sashForm = new Composite(this, SWT.EMBEDDED);

    // now we need a Swing object to put our chart into
    final Frame _plotControl = SWT_AWT.new_Frame(sashForm);

    // the y axis is common to hi & lo res. Format it here
    final NumberAxis yAxis = new NumberAxis("Degs");
    //   yAxis.setRange(0, 360);
    yAxis.setAutoRange(true);
    yAxis.setTickUnit(new NumberTickUnit(45));

    // create a date-formatting axis
    _dateAxis = new RelativeDateAxis();
    _dateAxis.setStandardTickUnits(DateAxisEditor.createStandardDateTickUnitsAsTickUnits());
    _dateAxis.setAutoRange(true);

    final XYItemRenderer theRenderer = new XYShapeRenderer();

    _thePlot = new XYPlot(null, _dateAxis, yAxis, theRenderer);
    _thePlot.setOrientation(PlotOrientation.HORIZONTAL);
    _thePlot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    _thePlot.setBackgroundPaint(Color.BLACK);
    theRenderer.setPlot(_thePlot);

    _dateAxis.setLabelPaint(Color.GREEN);
    _dateAxis.setTickLabelPaint(Color.GREEN);
    _dateAxis.setAxisLinePaint(Color.GREEN);

    yAxis.setLabelPaint(Color.GREEN);
    yAxis.setTickLabelPaint(Color.GREEN);

    _thePlotArea = new JFreeChart(null, _thePlot);
    _thePlotArea.setBackgroundPaint(Color.BLACK);
    _thePlotArea.setBorderPaint(Color.BLACK);

    // set the color of the area surrounding the plot
    // - naah, don't bother. leave it in the application background color.

    // ////////////////////////////////////////////////
    // put the holder into one of our special items
    // ////////////////////////////////////////////////
    _chartInPanel = new ChartPanel(_thePlotArea, true);

    _plotControl.add(_chartInPanel);

}

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

private JFreeChart createChart(IntervalXYDataset dataset, boolean isIntegral) {
    final String title = getTitle();
    final NumberAxis xAxis = new NumberAxis();
    if (isIntegral) {
        xAxis.setTickUnit(new NumberTickUnit(1.0));
    }/*www. j  a va2s  .c o  m*/
    if (metricType == MetricType.Ratio || metricType == MetricType.RecursiveRatio) {
        xAxis.setNumberFormatOverride(new PercentFormatter());
    }

    final XYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator();

    final XYItemRenderer renderer = new XYBarRenderer();
    renderer.setToolTipGenerator(tooltipGenerator);
    renderer.setURLGenerator(null);

    final ValueAxis yAxis = new NumberAxis();
    final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setRenderer(renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);

    return new JFreeChart(title, JFreeChartConstants.DEFAULT_TITLE_FONT, plot, true);
}

From source file:org.schreibubi.JCombinations.logic.visitors.ChartNodesVisitor.java

public void visit(Shmoo s) throws Exception {
    if (s.componentSelected(this.treePaths, OurTreeNode.MYSELF | OurTreeNode.PARENTS | OurTreeNode.CHILDS)) {
        NumberAxis xAxis = new NumberAxis(s.getTrim() + " [" + s.getXdataDefault().getUnit() + "]");
        xAxis.setAutoRangeIncludesZero(false);
        NumberAxis yAxis = new NumberAxis(
                s.getMeasure() + " [" + ((Ydata) s.getYdata().get(0)).getUnit() + "]");
        yAxis.setAutoRangeIncludesZero(false);
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRendererExtended(true, true);
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());

        this.dutData = new ArrayList<ArrayList<Double>>();
        this.dutName = new ArrayList<String>();
        for (int i = 0; i < s.getChildCount(); i++)
            (s.getChildAt(i)).accept(this);

        XYSeriesCollection xyseries = new XYSeriesCollection();
        ArrayList<Double> x = s.getXdataDefault().getXPositions();
        for (int j = 0; j < this.dutData.size(); j++) {
            ArrayList<Double> y = this.dutData.get(j);
            XYSeries xy = new XYSeries(this.dutName.get(j));
            for (int i = 0; i < y.size(); i++)
                xy.add(x.get(i), y.get(i));
            xyseries.addSeries(xy);//ww  w  .j  a v  a2s  . c o  m
        }

        XYPlot plot = new XYPlot(xyseries, xAxis, yAxis, renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
        plot.setDomainCrosshairVisible(true);
        plot.setRangeCrosshairVisible(true);
        Marker marker = s.getMarker();
        if (marker != null)
            plot.addRangeMarker(marker, Layer.BACKGROUND);
        ExtendedJFreeChart chart = new ExtendedJFreeChart(s.getDescription(), JFreeChart.DEFAULT_TITLE_FONT,
                plot, false);
        if (marker == null)
            chart.addSubtitle(new TextTitle(s.getSubtitle()));
        else
            chart.addSubtitle(new TextTitle(
                    s.getSubtitle() + " " + s.getValueAt(3) + "/" + s.getValueAt(4) + "/" + s.getValueAt(5)));

        chart.setTreePath(s.getTreePath());
        this.charts.add(chart);
    }

}

From source file:org.drools.planner.benchmark.core.statistic.calculatecount.CalculateCountProblemStatistic.java

protected void writeGraphStatistic() {
    XYSeriesCollection seriesCollection = new XYSeriesCollection();
    for (SingleBenchmark singleBenchmark : problemBenchmark.getSingleBenchmarkList()) {
        CalculateCountSingleStatistic singleStatistic = (CalculateCountSingleStatistic) singleBenchmark
                .getSingleStatistic(problemStatisticType);
        XYSeries series = new XYSeries(singleBenchmark.getSolverBenchmark().getName());
        for (CalculateCountSingleStatisticPoint point : singleStatistic.getPointList()) {
            long timeMillisSpend = point.getTimeMillisSpend();
            long calculateCountPerSecond = point.getCalculateCountPerSecond();
            series.add(timeMillisSpend, calculateCountPerSecond);
        }/*from   w  w  w . j a  v a 2s  .  c  o  m*/
        seriesCollection.addSeries(series);
    }
    NumberAxis xAxis = new NumberAxis("Time spend");
    xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
    NumberAxis yAxis = new NumberAxis("Calculate count per second");
    yAxis.setAutoRangeIncludesZero(false);
    XYItemRenderer renderer = new XYLineAndShapeRenderer();
    XYPlot plot = new XYPlot(seriesCollection, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart(problemBenchmark.getName() + " calculate count statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    graphStatisticFile = new File(problemBenchmark.getProblemReportDirectory(),
            problemBenchmark.getName() + "CalculateCountStatistic.png");
    OutputStream out = null;
    try {
        out = new FileOutputStream(graphStatisticFile);
        ImageIO.write(chartImage, "png", out);
    } catch (IOException e) {
        throw new IllegalArgumentException("Problem writing graphStatisticFile: " + graphStatisticFile, e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}