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() 

Source Link

Document

Creates a new XYPlot instance with no dataset, no axes and no renderer.

Usage

From source file:com.bdb.weather.display.day.DayXYPlotPane.java

private void createChartElements() {
    ///*from   ww w  .j  a  v  a 2  s  . co  m*/
    // Set up the Domain Axis (X)
    //
    plot = new XYPlot();
    dateAxis = new DateAxis("Time");
    dateAxis.setAutoRange(false);
    dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1, new SimpleDateFormat("h a")));
    dateAxis.setVerticalTickLabels(true);
    plot.setDomainAxis(dateAxis);
    plot.setRangeAxis(leftAxis);
    plot.setDataset(0, datasetLeft);
    if (rightAxis != null) {
        plot.setRangeAxis(1, rightAxis);
        plot.mapDatasetToRangeAxis(1, 1);
        plot.setDataset(1, datasetRight);
    }
    plot.setNoDataMessage("There is no data for the specified day");

    //
    // Set up the renderer to generate tool tips, not show shapes
    //
    XYLineAndShapeRenderer renderer = new XYLine3DRenderer();
    renderer.setBaseShapesVisible(false);
    renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    //renderer.setDefaultEntityRadius(1);
    plot.setRenderer(0, renderer);

    renderer = new XYLine3DRenderer();
    renderer.setBaseShapesVisible(false);
    renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    //renderer.setDefaultEntityRadius(1);
    plot.setRenderer(1, renderer);

    //
    // Setup the cross hairs that are displayed when the user clicks on the plot
    //
    plot.setRangeCrosshairLockedOnData(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(true);
    plot.setDomainCrosshairVisible(true);

    //
    // Create the chart that contains the plot and the panel that contains the chart
    //
    chart = new JFreeChart(plot);
    ChartFactory.getChartTheme().apply(chart);
    chartViewer = new ChartViewer(chart);

    chartViewer.setMaxHeight(500);
    chartViewer.setMaxWidth(800);

    //
    // Add the Day/Night indicator option to the chart panels context menu
    //
    ContextMenu menu = chartViewer.getContextMenu();

    displayMenu = new Menu("Display");

    dayNightItem = new CheckMenuItem("Day/Night Indicators");
    dayNightItem.setSelected(true);
    displayMenu.getItems().add(dayNightItem);
    dayNightItem.setOnAction(this);
    menu.getItems().add(displayMenu);
}

From source file:no.met.jtimeseries.chart.ChartPlotter.java

public ChartPlotter() {
    plotIndex = 0;
    rangeAxisIndex = 0;
    plot = new XYPlot();
}

From source file:de.bund.bfr.knime.nls.chart.ChartCreator.java

public JFreeChart createChart() throws ParseException {
    if (varX == null || varY == null) {
        return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, new XYPlot(), showLegend);
    }//from w ww.j  a  v  a  2 s .  c  o m

    List<String> idsToPaint;

    if (selectAll) {
        idsToPaint = new ArrayList<>(plotables.keySet());
    } else {
        idsToPaint = selectedIds;
    }

    NumberAxis xAxis = new NumberAxis(transformX.getName(varX));
    NumberAxis yAxis = new NumberAxis(transformY.getName(varY));
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    double usedMinX = Double.POSITIVE_INFINITY;
    double usedMaxX = Double.NEGATIVE_INFINITY;
    int index = 0;
    List<Color> defaultColors = ChartUtils.createColorList(idsToPaint.size());
    List<NamedShape> defaultShapes = ChartUtils.createShapeList(idsToPaint.size());

    for (String id : idsToPaint) {
        Plotable plotable = plotables.get(id);

        if (plotable == null) {
            continue;
        }

        if (plotable.isDataType()) {
            double[][] points = plotable.getDataPoints(varX, varY, transformX, transformY);

            if (points != null) {
                for (int i = 0; i < points[0].length; i++) {
                    usedMinX = Math.min(usedMinX, points[0][i]);
                    usedMaxX = Math.max(usedMaxX, points[0][i]);
                }
            }
        }

        if (plotable.isParamType()) {
            double minArg = transformX.to(MathUtils.nullToNan(plotable.getMinValues().get(varX)));
            double maxArg = transformX.to(MathUtils.nullToNan(plotable.getMaxValues().get(varX)));

            if (Double.isFinite(minArg)) {
                usedMinX = Math.min(usedMinX, minArg);
            }

            if (Double.isFinite(maxArg)) {
                usedMaxX = Math.max(usedMaxX, maxArg);
            }
        }
    }

    if (!Double.isFinite(usedMinX)) {
        usedMinX = 0.0;
    }

    if (!Double.isFinite(usedMaxX)) {
        usedMaxX = 100.0;
    }

    xAxis.setAutoRangeIncludesZero(false);
    yAxis.setAutoRangeIncludesZero(false);

    if (usedMinX == usedMaxX) {
        usedMinX -= 1.0;
        usedMaxX += 1.0;
    }

    if (useManualRange && minX < maxX && minY < maxY) {
        usedMinX = minX;
        usedMaxX = maxX;
        xAxis.setRange(new Range(minX, maxX));
        yAxis.setRange(new Range(minY, maxY));
    }

    for (String id : idsToPaint) {
        Plotable plotable = plotables.get(id);

        if (plotable == null) {
            continue;
        }

        plotable.setFunctionSteps(resolution);
        plotable.setInterpolator(interpolator);

        switch (plotable.getType()) {
        case DATA:
            plotData(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index));
            break;
        case FUNCTION:
            plotFunction(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        case DATA_FUNCTION:
            plotDataFunction(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        case DIFF:
            plotDiff(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        case DATA_DIFF:
            plotDataDiff(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        default:
            throw new RuntimeException("Unknown type of plotable: " + plotable.getType());
        }

        index++;
    }

    if (minToZero && !useManualRange) {
        Range xRange = xAxis.getRange();
        Range yRange = yAxis.getRange();

        if (xRange.getUpperBound() <= 0.0 || yRange.getUpperBound() <= 0.0) {
            return null;
        }

        xAxis.setRange(new Range(0.0, xRange.getUpperBound()));
        yAxis.setRange(new Range(0.0, yRange.getUpperBound()));
    }

    return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend);
}

From source file:playground.dgrether.analysis.charts.DgAvgDeltaMoneyGroupChart.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("Income [Chf / Year]");
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Money [Chf]");
    plot.setDomainAxis(xAxis);//w  w w  . j  av a  2s.c  o  m
    plot.setRangeAxis(yAxis);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    renderer2.setSeriesItemLabelsVisible(0, true);
    renderer2.setSeriesItemLabelGenerator(0, this.labelGenerator);
    plot.setDataset(0, this.dataset);
    renderer2.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer2.setSeriesOutlineStroke(0, new BasicStroke(3.0f));
    renderer2.setSeriesPaint(0, colorScheme.getColor(1, "a"));
    plot.setRenderer(0, renderer2);

    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    return chart;
}

From source file:net.sf.maltcms.chromaui.chromatogram2Dviewer.ui.panel.Chromatogram2DViewerPanel.java

/**
 * Creates new form Chromatogram2DViewerPanel
 *//*w ww .j a  va 2 s.  c om*/
public Chromatogram2DViewerPanel(InstanceContent topComponentInstanceContent, Lookup tcLookup,
        ADataset2D<IChromatogram2D, IScan2D> ds, PaintScale ps) {
    initComponents();
    this.content = topComponentInstanceContent;
    this.lookup = tcLookup;
    chart = new JFreeChart(new XYPlot());
    chartPanel = new ContextAwareChartPanel(chart, true, true, true, true, true);
    Cursor crosshairCursor = new Cursor(Cursor.CROSSHAIR_CURSOR);
    chartPanel.setCursor(crosshairCursor);
    //        chart.addProgressListener(cdxpanel);
    chartPanel.setInitialDelay(100);
    chartPanel.setDismissDelay(30000);
    chartPanel.setReshowDelay(0);
    chartPanel.setFocusable(true);
    jPanel2.add(chartPanel, BorderLayout.CENTER);
    content.add(chartPanel);
    addKeyListener(this);
    setPaintScale(ps);
}

From source file:playground.dgrether.signalsystems.analysis.DgGreenSplitPerIterationGraph.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("Iteration");
    xAxis.setRange(this.controllerConfig.getFirstIteration(), this.controllerConfig.getLastIteration() + 2);
    ValueAxis yAxis = this.axisBuilder.createValueAxis("GreenTime");
    //    yAxis.setRange(-0.05, 0.3);
    //    xAxis.setVisible(false);
    //    xAxis.setFixedAutoRange(1.0);
    plot.setDomainAxis(xAxis);/*www.ja  v a 2s .  c o  m*/
    plot.setRangeAxis(yAxis);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    renderer2.setSeriesItemLabelsVisible(0, true);
    //    renderer2.setSeriesItemLabelGenerator(0, this.labelGenerator);
    plot.setDataset(0, this.getDataset());
    renderer2.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer2.setSeriesOutlineStroke(0, new BasicStroke(3.0f));
    renderer2.setSeriesPaint(0, colorScheme.getColor(1, "a"));
    renderer2.setSeriesStroke(1, new BasicStroke(2.0f));
    renderer2.setSeriesOutlineStroke(1, new BasicStroke(3.0f));
    renderer2.setSeriesPaint(1, colorScheme.getColor(2, "a"));
    renderer2.setSeriesStroke(2, new BasicStroke(2.0f));
    renderer2.setSeriesOutlineStroke(2, new BasicStroke(3.0f));
    renderer2.setSeriesPaint(2, colorScheme.getColor(3, "a"));
    renderer2.setSeriesStroke(3, new BasicStroke(2.0f));
    renderer2.setSeriesOutlineStroke(3, new BasicStroke(3.0f));
    renderer2.setSeriesPaint(3, colorScheme.getColor(4, "a"));

    plot.setRenderer(0, renderer2);

    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    //    chart.removeLegend();
    return chart;
}

From source file:de.bund.bfr.knime.pmmlite.views.chart.ChartCreator.java

public void createEmptyChart() {
    setChart(new JFreeChart(new XYPlot()));
}

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

public SCHRGraph(ArrayList<Telemetry> telemetry[]) {
    super();//from  w  ww  .  jav a 2s  .  co  m
    this.telemetry = telemetry;

    final NumberAxis domainAxis = new NumberAxis("Time (h:m:s)");

    domainAxis.setVerticalTickLabels(true);
    domainAxis.setTickLabelPaint(Color.black);
    domainAxis.setAutoRange(true);

    domainAxis.setNumberFormatOverride(new NumberFormat() {
        @Override
        public StringBuffer format(double millis, StringBuffer toAppendTo, FieldPosition pos) {
            if (millis >= 3600000) {
                // hours, minutes and seconds
                return new StringBuffer(

                        String.format("%d:%d:%d", TimeUnit.MILLISECONDS.toHours((long) millis),
                                TimeUnit.MILLISECONDS.toMinutes(
                                        (long) millis - TimeUnit.MILLISECONDS.toHours((long) millis) * 3600000),
                                TimeUnit.MILLISECONDS.toSeconds((long) millis) - TimeUnit.MINUTES
                                        .toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis))));
            } else if (millis >= 60000) {
                // minutes and seconds
                return new StringBuffer(String.format("%d:%d", 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", 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;
        }
    });

    // create plot ...
    final XYItemRenderer powerRenderer = new StandardXYItemRenderer() {
        Stroke regularStroke = new BasicStroke(0.7f);
        Color color;

        public void setColor(Color color) {
            this.color = color;
        }

        @Override
        public Stroke getItemStroke(int row, int column) {
            return regularStroke;
        }

        @Override
        public Paint getItemPaint(int row, int column) {
            return orange;
        }
    };
    powerRenderer.setSeriesPaint(0, orange);
    plot = new XYPlot();
    plot.setRenderer(0, powerRenderer);
    plot.setRangeAxis(0, powerAxis);
    plot.setDomainAxis(domainAxis);

    // add a second dataset and renderer...
    final XYItemRenderer cadenceRenderer = new StandardXYItemRenderer() {
        Stroke regularStroke = new BasicStroke(0.7f);
        Color color;

        public void setColor(Color color) {
            this.color = color;
        }

        @Override
        public Stroke getItemStroke(int row, int column) {
            return regularStroke;
        }

        @Override
        public Paint getItemPaint(int row, int column) {
            return cornflower;
        }

        public Shape lookupLegendShape(int series) {
            return new Rectangle(15, 15);
        }
    };

    final ValueAxis cadenceAxis = new NumberAxis(userPrefs.messages.getString("cDrpm"));
    cadenceAxis.setRange(0, 200);

    // arguments of new XYLineAndShapeRenderer are to activate or deactivate
    // the display of points or line. Set first argument to true if you want
    // to draw lines between the points for e.g.
    plot.setRenderer(1, cadenceRenderer);
    plot.setRangeAxis(1, cadenceAxis);
    plot.mapDatasetToRangeAxis(1, 1);
    cadenceRenderer.setSeriesPaint(0, cornflower);

    // add a third dataset and renderer...
    final XYItemRenderer hrRenderer = new StandardXYItemRenderer() {
        Stroke regularStroke = new BasicStroke(0.7f);
        Color color;

        public void setColor(Color color) {
            this.color = color;
        }

        @Override
        public Stroke getItemStroke(int row, int column) {
            return regularStroke;
        }

        @Override
        public Paint getItemPaint(int row, int column) {
            return straw;
        }

    };

    // arguments of new XYLineAndShapeRenderer are to activate or deactivate
    // the display of points or line. Set first argument to true if you want
    // to draw lines between the points for e.g.
    final ValueAxis heartRateAxis = new NumberAxis(userPrefs.messages.getString("hrBpm"));
    heartRateAxis.setRange(0, 200);

    plot.setRenderer(2, hrRenderer);
    hrRenderer.setSeriesPaint(0, straw);

    plot.setRangeAxis(2, heartRateAxis);
    plot.mapDatasetToRangeAxis(2, 2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setBackgroundPaint(Color.DARK_GRAY);
    // return a new chart containing the overlaid plot...
    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    chart.getLegend().setBackgroundPaint(Color.gray);

    chartPanel = new ChartPanel(chart);

    // TODO: maybe remember sizes set by user?
    this.setPreferredSize(new Dimension(1200, 500));
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setBackground(Color.gray);

    setLayout(new BorderLayout());
    add(chartPanel, BorderLayout.CENTER);

    SmoothingPanel smoothingPanel = new SmoothingPanel(this);
    add(smoothingPanel, BorderLayout.SOUTH);

    //infoPanel = new InfoPanel();
    //add(infoPanel, BorderLayout.NORTH);
    setVisible(true);
}

From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.panel.Chromatogram1DHeatmapViewerPanel.java

/**
 * Creates new form Chromatogram2DViewerPanel
 *///from w  ww.jav  a  2  s . c  o m
public Chromatogram1DHeatmapViewerPanel(InstanceContent topComponentInstanceContent, Lookup tcLookup,
        ADataset2D<IChromatogram1D, IScan> ds) {
    initComponents();
    this.content = topComponentInstanceContent;
    this.lookup = tcLookup;
    chart = new JFreeChart(new XYPlot());
    chartPanel = new ContextAwareChartPanel(chart, true, true, true, true, true);
    Cursor crosshairCursor = new Cursor(Cursor.CROSSHAIR_CURSOR);
    chartPanel.setCursor(crosshairCursor);
    //        chart.addProgressListener(cdxpanel);
    chartPanel.setInitialDelay(100);
    chartPanel.setDismissDelay(30000);
    chartPanel.setReshowDelay(0);
    chartPanel.setFocusable(true);
    jPanel2.add(chartPanel, BorderLayout.CENTER);
    content.add(chartPanel);
    addKeyListener(this);
    dataRange = DatasetUtilities.findDomainBounds(ds);
}

From source file:playground.dgrether.analysis.charts.DgAvgDeltaUtilsModeQuantilesChart.java

@Override
public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("% of Population Sorted by Income");
    xAxis.setRange(0.0, 102.0);//from  w w  w.j  ava  2s. c o m
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Utils [Utils]");
    yAxis.setRange(-0.05, 0.3);
    plot.setDomainAxis(xAxis);
    plot.setRangeAxis(yAxis);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    plot.setDataset(0, this.dataset);
    for (int i = 0; i <= 3; i++) {
        renderer2.setSeriesStroke(i, new BasicStroke(2.0f));
        renderer2.setSeriesOutlineStroke(i, new BasicStroke(3.0f));
        renderer2.setSeriesPaint(i, colorScheme.getColor(i + 1, "a"));
    }
    plot.setRenderer(0, renderer2);

    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    return chart;
}