Example usage for org.jfree.chart.axis NumberAxis setRange

List of usage examples for org.jfree.chart.axis NumberAxis setRange

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberAxis setRange.

Prototype

public void setRange(double lower, double upper) 

Source Link

Document

Sets the range for the axis and sends a change event to all registered listeners.

Usage

From source file:be.nbb.demetra.dfm.output.simulation.RealTimePerspGraphView.java

private void showDetail(Graphs g) {
    XYPlot plot = detailChart.getXYPlot();

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickLabelPaint(Color.GRAY);
    plot.setRangeAxis(yAxis);// w  w w  .j  av a 2s  .  com

    NumberAxis xAxis = new NumberAxis();
    xAxis.setTickLabelPaint(Color.GRAY);
    xAxis.setTickUnit(new NumberTickUnit(10));
    xAxis.setRange(horizons.get(0), horizons.get(horizons.size() - 1));
    xAxis.setVerticalTickLabels(true);
    plot.setDomainAxis(xAxis);

    plot.setDataset(TRUE_DATA_INDEX, new BasicXYDataset(Collections.singletonList(g.S1_)));
    plot.setDataset(FCTS_INDEX, new BasicXYDataset(Collections.singletonList(g.S2_)));
    plot.setDataset(ARIMA_DATA_INDEX, new BasicXYDataset(Collections.singletonList(g.S3_)));

    rescaleAxis((NumberAxis) plot.getRangeAxis());

    detailChart.setTitle(g.label_);
    chartPanel.setChart(detailChart);
    chartPanel.setToolTipText("Right click to show complete data");
    chartPanel.setPopupMenu(buildMenu().getPopupMenu());
    onColorSchemeChanged();

    selectedGraph = g;
}

From source file:pl.dpbz.poid.zadanie3.GUI.java

private void drawChartOfSoundSignal(Integer[] ints, double samplingFrequency) {
    //Rysowanie wykresu sygnau dwikowego
    final XYSeries dist = new XYSeries("P0");
    int index = 0;
    for (Integer i : ints) {
        dist.add(index / samplingFrequency, i);
        index++;//from   www  .j a  va  2  s.c  om
    }
    final XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(dist);

    JFreeChart chart = ChartFactory.createXYLineChart(f.getName(), "index", "Distance", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);
    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    NumberAxis domain = (NumberAxis) xyPlot.getRangeAxis();
    domain.setRange(-32768, 32768);
    //ChartDrawer.drawChart(chart);

    ChartPanel cp4 = new ChartPanel(chart);
    this.chartJPanel4.removeAll();
    this.chartJPanel4.setLayout(new java.awt.BorderLayout());
    this.chartJPanel4.add(cp4, BorderLayout.CENTER);
    this.chartJPanel4.validate();
}

From source file:org.locationtech.udig.processingtoolbox.tools.HistogramDialog.java

private void updateChart(SimpleFeatureCollection features, String field) {
    int bin = spinner.getSelection();

    double[] values = getValues(features, field);
    HistogramDataset dataset = new HistogramDataset();
    dataset.addSeries(field, values, bin, minMaxVisitor.getMinX(), minMaxVisitor.getMaxX());
    dataset.setType(histogramType);//from w  w  w  .j  a  v  a2s.  c  o m

    JFreeChart chart = ChartFactory.createHistogram(EMPTY, null, null, dataset, PlotOrientation.VERTICAL, false,
            false, false);

    // 1. Create a single plot containing both the scatter and line
    chart.setBackgroundPaint(java.awt.Color.WHITE);
    chart.setBorderVisible(false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setForegroundAlpha(0.85F);
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setOrientation(PlotOrientation.VERTICAL);

    plot.setDomainGridlinePaint(java.awt.Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(java.awt.Color.LIGHT_GRAY);

    int fontStyle = java.awt.Font.BOLD;
    FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0];

    NumberAxis valueAxis = new NumberAxis(cboField.getText());
    valueAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    valueAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10));

    valueAxis.setAutoRange(false);
    valueAxis.setRange(minMaxVisitor.getMinX(), minMaxVisitor.getMaxX());

    String rangeAxisLabel = histogramType == HistogramType.FREQUENCY ? "Frequency" : "Ratio"; //$NON-NLS-1$ //$NON-NLS-2$
    NumberAxis rangeAxis = new NumberAxis(rangeAxisLabel);
    rangeAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    rangeAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10));
    if (histogramType == HistogramType.FREQUENCY) {
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setShadowVisible(false);
    CustomXYBarPainter.selectedColumn = -1; // init
    renderer.setBarPainter(new CustomXYBarPainter());
    renderer.setAutoPopulateSeriesFillPaint(true);
    renderer.setAutoPopulateSeriesPaint(true);
    renderer.setShadowXOffset(3);
    renderer.setMargin(0.01);
    renderer.setBaseItemLabelsVisible(true);

    ItemLabelPosition pos = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_CENTER);
    renderer.setBasePositiveItemLabelPosition(pos);

    XYToolTipGenerator plotToolTip = new StandardXYToolTipGenerator();
    renderer.setBaseToolTipGenerator(plotToolTip);

    // color
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, java.awt.Color.GRAY, 0.0f, 0.0f,
            java.awt.Color.LIGHT_GRAY);
    renderer.setSeriesPaint(0, gp0);

    plot.setDomainAxis(0, valueAxis);
    plot.setRangeAxis(0, rangeAxis);

    // 3. Setup line
    // Create the line data, renderer, and axis
    XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only
    lineRenderer.setSeriesPaint(0, java.awt.Color.RED);
    lineRenderer.setSeriesStroke(0, new BasicStroke(2f));

    // Set the line data, renderer, and axis into plot
    NumberAxis xLineAxis = new NumberAxis(EMPTY);
    xLineAxis.setTickMarksVisible(false);
    xLineAxis.setTickLabelsVisible(false);
    xLineAxis.setAutoRange(false);

    NumberAxis yLineAxis = new NumberAxis(EMPTY);
    yLineAxis.setTickMarksVisible(false);
    yLineAxis.setTickLabelsVisible(false);
    yLineAxis.setAutoRange(false);

    double maxYValue = Double.MIN_VALUE;
    for (int i = 0; i < dataset.getItemCount(0); i++) {
        maxYValue = Math.max(maxYValue, dataset.getYValue(0, i));
    }

    XYSeriesCollection lineDatset = new XYSeriesCollection();

    // Vertical Average
    XYSeries vertical = new XYSeries("Average"); //$NON-NLS-1$
    vertical.add(minMaxVisitor.getAverageX(), 0);
    vertical.add(minMaxVisitor.getAverageX(), maxYValue);
    lineDatset.addSeries(vertical);

    plot.setDataset(1, lineDatset);
    plot.setRenderer(1, lineRenderer);
    plot.setDomainAxis(1, xLineAxis);
    plot.setRangeAxis(1, yLineAxis);

    // Map the line to the second Domain and second Range
    plot.mapDatasetToDomainAxis(1, 0);
    plot.mapDatasetToRangeAxis(1, 0);

    chartComposite.setChart(chart);
    chartComposite.forceRedraw();
}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java

protected void resetRenderer(final IScope scope, final String serieid) {
    final XYBlockRenderer newr = (XYBlockRenderer) this.getOrCreateRenderer(scope, serieid);

    // newr.setSeriesStroke(0, new BasicStroke(0));
    final ChartDataSeries myserie = this.getChartdataset().getDataSeries(scope, serieid);

    if (myserie.getMycolor() != null) {
        newr.setSeriesPaint(0, myserie.getMycolor());
    }//w  ww. j  a v  a  2  s  .  c  om
    if (myserie.getSValues(scope).size() > 0) {
        final double maxval = Collections.max(myserie.getSValues(scope));
        final double minval = Collections.min(myserie.getSValues(scope));
        Color cdeb = new Color(0, 0, 0, 0);
        if (myserie.getMyMincolor() != null)
            cdeb = myserie.getMyMincolor();
        Color cend = new Color(0.9f, 0.9f, 0.9f, 1.0f);
        if (myserie.getMycolor() != null)
            cend = myserie.getMycolor();

        LookupPaintScale paintscale = createLUT(100, (float) minval, (float) maxval, cdeb, cend);
        if (myserie.getMyMedcolor() != null)
            paintscale = createLUT(100, (float) minval, (float) maxval, cdeb, myserie.getMyMedcolor(), cend);

        newr.setPaintScale(paintscale);

        final NumberAxis scaleAxis = new NumberAxis(myserie.getName());
        scaleAxis.setAxisLinePaint(this.axesColor);
        scaleAxis.setTickMarkPaint(this.axesColor);
        scaleAxis.setTickLabelFont(this.getTickFont());
        scaleAxis.setRange(minval, maxval);
        scaleAxis.setAxisLinePaint(axesColor);
        scaleAxis.setLabelFont(getLabelFont());
        if (textColor != null) {
            scaleAxis.setLabelPaint(textColor);
            scaleAxis.setTickLabelPaint(textColor);
        }
        if (!this.getXTickValueVisible(scope)) {
            scaleAxis.setTickMarksVisible(false);
            scaleAxis.setTickLabelsVisible(false);

        }

        final PaintScaleLegend legend = new PaintScaleLegend(paintscale, scaleAxis);
        legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
        legend.setAxisOffset(5.0);
        // legend.setMargin(new RectangleInsets(5, 5, 5, 5));
        // legend.setFrame(new BlockBorder(Color.red));
        // legend.setPadding(new RectangleInsets(10, 10, 10, 10));
        // legend.setStripWidth(10);
        legend.setPosition(RectangleEdge.RIGHT);
        legend.setBackgroundPaint(this.backgroundColor);
        // ArrayList<PaintScaleLegend> caxe=new
        // ArrayList<PaintScaleLegend>();
        // caxe.add(legend);
        // chart.setSubtitles(caxe);
        if (!this.series_label_position.equals("none"))
            chart.addSubtitle(legend);

    }
}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java

@Override
protected void resetSerie(final IScope scope, final String serieid) {
    // TODO Auto-generated method stub
    this.createNewSerie(scope, serieid);
    final ChartDataSeries dataserie = chartdataset.getDataSeries(scope, serieid);
    final MatrixSeries serie = ((MatrixSeriesCollection) jfreedataset
            .get(IdPosition.get(dataserie.getSerieId(scope)))).getSeries(0);
    final ArrayList<Double> XValues = dataserie.getXValues(scope);
    final ArrayList<Double> YValues = dataserie.getYValues(scope);
    final ArrayList<Double> SValues = dataserie.getSValues(scope);
    final NumberAxis domainAxis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getDomainAxis();
    if (XValues.size() == 0) {
        if (!usexrangeinterval && !usexrangeminmax) {
            domainAxis.setAutoRange(false);
            domainAxis.setRange(-0.5, XValues.size() + 0.5);
        }/*  w w  w.j  ava2 s. c  om*/

    }
    final NumberAxis rangeAxis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getRangeAxis();
    if (YValues.size() == 0) {
        if (!useyrangeinterval && !useyrangeminmax) {
            rangeAxis.setAutoRange(false);
            rangeAxis.setRange(-0.5, YValues.size() + 0.5);
        }

    }
    //      final NumberAxis domainAxis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getDomainAxis();
    //      final NumberAxis rangeAxis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getRangeAxis();

    if (XValues.size() > 0) {
        domainAxis.setAutoRange(false);
        rangeAxis.setAutoRange(false);
        domainAxis.setTickLabelsVisible(this.getXTickValueVisible(scope));
        domainAxis.setTickMarksVisible(this.getXTickValueVisible(scope));
        rangeAxis.setTickLabelsVisible(this.getYTickValueVisible(scope));
        rangeAxis.setTickMarksVisible(this.getYTickValueVisible(scope));
        for (int i = 0; i < XValues.size(); i++) {

            if (XValues.get(i) > domainAxis.getUpperBound()) {
                if (!usexrangeinterval && !usexrangeminmax) {
                    domainAxis.setAutoRange(false);
                    domainAxis.setRange(-0.5, YValues.get(i) + 0.5);
                }

            }
            if (YValues.get(i) > rangeAxis.getUpperBound()) {
                if (!useyrangeinterval && !useyrangeminmax) {
                    rangeAxis.setAutoRange(false);
                    rangeAxis.setRange(-0.5, YValues.get(i) + 0.5);
                }

            }

            serie.update(YValues.get(i).intValue(), XValues.get(i).intValue(), SValues.get(i).doubleValue());
        }
    }
    this.resetRenderer(scope, serieid);

}

From source file:com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.Classes.FindMaxpoint.java

/**
 * Creates a chart.//w w w  . ja  v  a 2  s .  com
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
public JFreeChart createChart() {

    //http://www.java2s.com/Code/Java/Chart/JFreeChartDualAxisDemo2.htm
    String xlabel = "Delay (ps)";
    String ylabel = "Signal (DN)";

    // create the chart with findmaxpoint results
    final JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            xlabel, // x axis label
            ylabel, // y axis label
            findMaxpointData_, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );

    final XYPlot plot = chart.getXYPlot();
    // deal with axes and add second dataset
    final NumberAxis yaxis1 = (NumberAxis) plot.getRangeAxis();
    yaxis1.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
    yaxis1.setLabelFont(new Font("Dialog", Font.PLAIN, 10));
    final NumberAxis yaxis2 = new NumberAxis(null);
    final NumberAxis xaxis = (NumberAxis) plot.getDomainAxis();
    xaxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
    xaxis.setLabelFont(new Font("Dialog", Font.PLAIN, 10));
    plot.setRangeAxis(1, yaxis2);
    plot.setDataset(1, gatePositionData_);
    plot.mapDatasetToRangeAxis(1, 1);
    yaxis1.setRange(0, 5000);
    yaxis2.setRange(-1, 1);
    yaxis2.setTickLabelsVisible(false);
    xaxis.setRange(0, 16666);

    // deal with visuals

    final XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(true, true);
    renderer1.setSeriesPaint(0, Color.RED);
    renderer1.setSeriesStroke(0, new BasicStroke(3));

    //        renderer1.setBaseShapesVisible(true);
    //        renderer1.setSeriesShape(0, ShapeUtilities.createDiagonalCross(4,1));

    plot.setRenderer(0, renderer1);

    //        final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(false, true);
    renderer2.setSeriesPaint(0, Color.CYAN);
    renderer2.setSeriesShapesFilled(0, Boolean.TRUE);
    renderer2.setBaseShapesVisible(true);
    renderer2.setShape(new Rectangle(-2, -100, 4, 200));
    renderer2.setOutlineStroke(new BasicStroke(1));
    renderer2.setOutlinePaint(Color.GRAY);
    renderer2.setUseOutlinePaint(true);
    plot.setRenderer(1, renderer2);

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    //                
    return chart;

}

From source file:org.gwaspi.gui.reports.SampleQAHetzygPlotZoom.java

private JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createScatterPlot("Heterozygosity vs. Missing Ratio",
            "Heterozygosity Ratio", "Missing Ratio", dataset, PlotOrientation.VERTICAL, true, false, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);

    // CHART BACKGROUD COLOR
    chart.setBackgroundPaint(Color.getHSBColor(0.1f, 0.1f, 1.0f)); // Hue, saturation, brightness
    plot.setBackgroundPaint(PLOT_MANHATTAN_BACKGROUND); // Hue, saturation, brightness 9

    // GRIDLINES/*from ww  w. j av  a2  s .  c o  m*/
    plot.setDomainGridlineStroke(new BasicStroke(0.0f));
    plot.setDomainMinorGridlineStroke(new BasicStroke(0.0f));
    plot.setDomainGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker().darker()); // Hue, saturation, brightness 7
    plot.setDomainMinorGridlinePaint(PLOT_MANHATTAN_BACKGROUND); // Hue, saturation, brightness 9
    plot.setRangeGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeMinorGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker().darker()); // Hue, saturation, brightness 7
    plot.setRangeMinorGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker()); // Hue, saturation, brightness 8

    plot.setDomainMinorGridlinesVisible(true);
    plot.setRangeMinorGridlinesVisible(true);

    // DOTS RENDERER
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, PLOT_MANHATTAN_DOTS);
    //      renderer.setSeriesOutlinePaint(0, Color.DARK_GRAY);
    //      renderer.setUseOutlinePaint(true);
    // Set dot shape of the currently appended Series
    renderer.setSeriesShape(0, new Rectangle2D.Double(-1, -1, 2, 2));

    renderer.setSeriesVisibleInLegend(0, false);

    // AXIS
    double maxHetzy = 0.005;
    for (int i = 0; i < dataset.getItemCount(0); i++) {
        if (maxHetzy < dataset.getXValue(0, i)) {
            maxHetzy = dataset.getXValue(0, i);
        }
    }
    NumberAxis hetzyAxis = (NumberAxis) plot.getDomainAxis();
    hetzyAxis.setAutoRangeIncludesZero(true);
    hetzyAxis.setAxisLineVisible(true);
    hetzyAxis.setTickLabelsVisible(true);
    hetzyAxis.setTickMarksVisible(true);
    hetzyAxis.setRange(0, maxHetzy * 1.1);

    double maxMissrat = 0.005;
    for (int i = 0; i < dataset.getItemCount(0); i++) {
        if (maxMissrat < dataset.getYValue(0, i)) {
            maxMissrat = dataset.getYValue(0, i);
        }
    }
    NumberAxis missratAxis = (NumberAxis) plot.getRangeAxis();
    missratAxis.setAutoRangeIncludesZero(true);
    missratAxis.setAxisLineVisible(true);
    missratAxis.setTickLabelsVisible(true);
    missratAxis.setTickMarksVisible(true);
    missratAxis.setRange(0, maxMissrat * 1.1);

    // Add significance Threshold to subplot
    final Marker missingThresholdLine = new ValueMarker(missingThreshold);
    missingThresholdLine.setPaint(Color.blue);

    final Marker hetzyThresholdLine = new ValueMarker(hetzyThreshold);
    hetzyThresholdLine.setPaint(Color.blue);

    // Add legend to hetzyThreshold
    hetzyThresholdLine.setLabel("hetzyg. threshold = " + hetzyThreshold);
    missingThresholdLine.setLabel("missing. threshold = " + missingThreshold);
    hetzyThresholdLine.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    hetzyThresholdLine.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    missingThresholdLine.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
    missingThresholdLine.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    plot.addRangeMarker(missingThresholdLine); // THIS FOR MISSING RATIO
    plot.addDomainMarker(hetzyThresholdLine); // THIS FOR HETZY RATIO

    // Marker label if below hetzyThreshold
    XYItemRenderer lblRenderer = plot.getRenderer();

    // THRESHOLD AND SELECTED LABEL GENERATOR
    MySeriesItemLabelGenerator lblGenerator = new MySeriesItemLabelGenerator(hetzyThreshold, missingThreshold);
    lblRenderer.setSeriesItemLabelGenerator(0, lblGenerator);
    lblRenderer.setSeriesItemLabelFont(0, new Font("SansSerif", Font.PLAIN, 10));
    lblRenderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.BOTTOM_LEFT, TextAnchor.BOTTOM_LEFT, 2 * Math.PI));

    // TOOLTIP GENERATOR
    MyXYToolTipGenerator tooltipGenerator = new MyXYToolTipGenerator();

    lblRenderer.setBaseToolTipGenerator(tooltipGenerator);

    lblRenderer.setSeriesItemLabelsVisible(0, true);

    return chart;
}

From source file:loci.slim2.process.interactive.ui.DefaultDecayGraph.java

/**
 * Creates the chart/*from   w w  w .  j a va 2 s  .  co  m*/
 *
 * @param bins number of bins
 * @param timeInc time increment per bin
 * @return the chart
 */
JFreeChart createCombinedChart(final int bins, final double timeInc) {

    // create empty chart data sets
    decayDataset = new XYSeriesCollection();
    residualDataset = new XYSeriesCollection();

    // make a common horizontal axis for both sub-plots
    final NumberAxis timeAxis = new NumberAxis(TIME_AXIS_LABEL);
    timeAxis.setLabel(UNITS_LABEL);
    timeAxis.setRange(0.0, (bins - 1) * timeInc);

    // make a vertically combined plot
    final CombinedDomainXYPlot parent = new CombinedDomainXYPlot(timeAxis);

    // create decay sub-plot
    NumberAxis photonAxis;
    if (logarithmic) {
        photonAxis = new LogarithmicAxis(PHOTON_AXIS_LABEL);
    } else {
        photonAxis = new NumberAxis(PHOTON_AXIS_LABEL);
    }
    final XYSplineRenderer decayRenderer = new XYSplineRenderer();
    decayRenderer.setSeriesShapesVisible(0, false);
    decayRenderer.setSeriesShapesVisible(1, false);
    decayRenderer.setSeriesLinesVisible(2, false);
    decayRenderer.setSeriesShape(2, new Ellipse2D.Float(-1.0f, -1.0f, 2.0f, 2.0f));

    decayRenderer.setSeriesPaint(0, PROMPT_COLOR);
    decayRenderer.setSeriesPaint(1, FITTED_COLOR);
    decayRenderer.setSeriesPaint(2, DECAY_COLOR);

    decaySubPlot = new XYPlot(decayDataset, null, photonAxis, decayRenderer);
    decaySubPlot.setDomainCrosshairVisible(true);
    decaySubPlot.setRangeCrosshairVisible(true);

    // add decay sub-plot to parent
    parent.add(decaySubPlot, DECAY_WEIGHT);

    // create residual sub-plot
    final NumberAxis residualAxis = new NumberAxis(RESIDUAL_AXIS_LABEL);
    final XYSplineRenderer residualRenderer = new XYSplineRenderer();
    residualRenderer.setSeriesPaint(0, RESIDUAL_COLOR);
    residualRenderer.setSeriesLinesVisible(0, false);
    residualRenderer.setSeriesShape(0, new Ellipse2D.Float(-1.0f, -1.0f, 2.0f, 2.0f));

    final XYPlot residualSubPlot = new XYPlot(residualDataset, null, residualAxis, residualRenderer);
    residualSubPlot.setDomainCrosshairVisible(true);
    residualSubPlot.setRangeCrosshairVisible(true);
    residualSubPlot.setFixedLegendItems(null);

    // add residual sub-plot to parent
    parent.add(residualSubPlot, RESIDUAL_WEIGHT);

    // now make the top level JFreeChart
    final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, parent, true);
    chart.removeLegend();

    return chart;
}

From source file:com.prezerak.windmill.gui.AveragesPanel.java

private void plotEverything() {
    try {//www  . j a  va2 s  . c  om
        final XYPlot plot = chart.getXYPlot();

        ValueAxis domainAxis = plot.getDomainAxis();
        plot.getDomainAxis().setLowerMargin(0);
        plot.getDomainAxis().setUpperMargin(0);
        plot.getDomainAxis().setAutoRange(true);

        if (domainAxis instanceof DateAxis) {
            DateAxis axis = (DateAxis) domainAxis;
            // customise axis here...
            //axis.setRange(new Date(startDate), new Date(endDate));
            long startT = datasetVel.getDataItem(0).getPeriod().getLastMillisecond();
            long endT = datasetVel.getDataItem(datasetVel.getItemCount() - 1).getPeriod().getLastMillisecond();
            ;
            DateFormat formatter;
            long duration = endT - startT;
            long _24hrs = 1000 * 60 * 60 * 24;
            long _3mins = 1000 * 60 * 3;

            if (duration > _24hrs) {
                formatter = new SimpleDateFormat("HH:mm dd-MMM");
            } else if (endDate - startDate > _3mins && endDate - startDate <= _24hrs)
                formatter = new SimpleDateFormat("HH:mm");
            else //smaller than 3mins
                formatter = new SimpleDateFormat("HH:mm:ss");
            axis.setDateFormatOverride(formatter);
        }

        TimeSeriesCollection seriesVel = new TimeSeriesCollection();
        seriesVel.addSeries(datasetVel);
        plot.setDataset(0, seriesVel);
        final NumberAxis velRangeAxis = (NumberAxis) plot.getRangeAxis();
        velRangeAxis.setRange(0.0, maxY);
        plot.setRangeAxis(velRangeAxis);
        plot.mapDatasetToRangeAxis(0, 0);
        XYLineAndShapeRenderer velocityRenderer = (XYLineAndShapeRenderer) plot.getRenderer(0);
        velocityRenderer.setBaseShapesVisible(true);
        velocityRenderer.setBaseShapesFilled(false);
        velocityRenderer.setBaseToolTipGenerator(
                new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                        new SimpleDateFormat("dd-MM-yy, hh:mm:ss a"), new DecimalFormat("00.0")));
        velocityRenderer.setSeriesPaint(0, Color.BLACK);

        if (!rdbtnVelocity.isSelected()) {
            velocityRenderer.setSeriesVisible(0, false);
        } else {
            velocityRenderer.setSeriesVisible(0, true);
        }

        TimeSeriesCollection seriesDir = new TimeSeriesCollection();
        seriesDir.addSeries(datasetDir);
        plot.setDataset(1, seriesDir);
        final ValueAxis dirRangeAxis = new NumberAxis("Direction");
        dirRangeAxis.setRange(0.0, 370.0);
        plot.setRangeAxis(1, dirRangeAxis);
        plot.mapDatasetToRangeAxis(1, 1);

        XYLineAndShapeRenderer dirRenderer = (XYLineAndShapeRenderer) plot.getRenderer(1);
        if (dirRenderer == null)
            dirRenderer = new XYLineAndShapeRenderer();
        dirRenderer.setBaseToolTipGenerator(
                new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                        new SimpleDateFormat("dd-MM-yy, hh:mm:ss a"), new DecimalFormat("00.0")));

        plot.setRenderer(1, dirRenderer);
        dirRenderer.setSeriesPaint(0, Color.BLUE);

        if (!rdbtnDirection.isSelected()) {
            dirRenderer.setSeriesVisible(0, false);
        } else {
            dirRenderer.setSeriesVisible(0, true);
        }

        final ValueAxis alarmsRangeAxis = new NumberAxis("Alarms");
        alarmsRangeAxis.setRange(0.0, 1);
        alarmsRangeAxis.setVisible(false);

        XYBarRenderer gustRenderer = null;

        TimePeriodValuesCollection seriesGust = new TimePeriodValuesCollection(datasetGust);
        plot.setDataset(2, seriesGust);

        plot.setRangeAxis(2, alarmsRangeAxis);
        plot.mapDatasetToRangeAxis(2, 2);

        gustRenderer = (XYBarRenderer) plot.getRenderer(2);
        if (gustRenderer == null)
            gustRenderer = new XYBarRenderer();
        plot.setRenderer(2, gustRenderer);
        gustRenderer.setSeriesPaint(0, Color.PINK);

        if ((rdbtnVelocity.isSelected() || rdbtnDirection.isSelected()) && rdbtnGust.isSelected())
            gustRenderer.setSeriesVisible(0, true);
        else
            gustRenderer.setSeriesVisible(0, false);

        XYBarRenderer higherRenderer = null;
        TimePeriodValuesCollection seriesHigher = new TimePeriodValuesCollection(datasetHigher);
        plot.setDataset(3, seriesHigher);

        plot.setRangeAxis(3, alarmsRangeAxis);
        plot.mapDatasetToRangeAxis(3, 2);

        higherRenderer = (XYBarRenderer) plot.getRenderer(3);
        if (higherRenderer == null)
            higherRenderer = new XYBarRenderer();
        plot.setRenderer(3, higherRenderer);
        higherRenderer.setSeriesPaint(0, Color.RED);
        if ((rdbtnVelocity.isSelected() || rdbtnDirection.isSelected()) && rdbtnHigher.isSelected())

            higherRenderer.setSeriesVisible(0, true);

        else
            higherRenderer.setSeriesVisible(0, false);

        TimePeriodValuesCollection seriesHigh = new TimePeriodValuesCollection(datasetHigh);
        plot.setDataset(4, seriesHigh);

        plot.setRangeAxis(4, alarmsRangeAxis);
        plot.mapDatasetToRangeAxis(4, 2);

        XYBarRenderer highRenderer = (XYBarRenderer) plot.getRenderer(4);
        if (highRenderer == null)
            highRenderer = new XYBarRenderer();
        plot.setRenderer(4, highRenderer);
        highRenderer.setSeriesPaint(0, new Color(206, 33, 85));
        if ((rdbtnVelocity.isSelected() || rdbtnDirection.isSelected()) && rdbtnHigh.isSelected())

            highRenderer.setSeriesVisible(0, true);
        else
            highRenderer.setSeriesVisible(0, false);

    } catch (OutOfMemoryError e) {
        WindMill.logger.warn("Out of Memory in plotEverything");
    }

}

From source file:loci.slim.ui.DecayGraph.java

/**
 * Creates the chart/*from w  w  w .  ja  v a 2  s . co m*/
 *
 * @param bins number of bins
 * @param timeInc time increment per bin
 * @return the chart
 */
JFreeChart createCombinedChart(final int bins, final double timeInc) {

    // create empty chart data sets
    _decayDataset = new XYSeriesCollection();
    _residualDataset = new XYSeriesCollection();

    // make a common horizontal axis for both sub-plots
    final NumberAxis timeAxis = new NumberAxis(TIME_AXIS_LABEL);
    timeAxis.setLabel(UNITS_LABEL);
    timeAxis.setRange(0.0, (bins - 1) * timeInc);

    // make a vertically combined plot
    final CombinedDomainXYPlot parent = new CombinedDomainXYPlot(timeAxis);

    // create decay sub-plot
    NumberAxis photonAxis;
    if (_logarithmic) {
        photonAxis = new LogarithmicAxis(PHOTON_AXIS_LABEL);
    } else {
        photonAxis = new NumberAxis(PHOTON_AXIS_LABEL);
    }
    final XYSplineRenderer decayRenderer = new XYSplineRenderer();
    decayRenderer.setSeriesShapesVisible(0, false);
    decayRenderer.setSeriesShapesVisible(1, false);
    decayRenderer.setSeriesLinesVisible(2, false);
    decayRenderer.setSeriesShape(2, new Ellipse2D.Float(-1.0f, -1.0f, 2.0f, 2.0f));

    decayRenderer.setSeriesPaint(0, PROMPT_COLOR);
    decayRenderer.setSeriesPaint(1, FITTED_COLOR);
    decayRenderer.setSeriesPaint(2, DECAY_COLOR);

    _decaySubPlot = new XYPlot(_decayDataset, null, photonAxis, decayRenderer);
    _decaySubPlot.setDomainCrosshairVisible(true);
    _decaySubPlot.setRangeCrosshairVisible(true);

    // add decay sub-plot to parent
    parent.add(_decaySubPlot, DECAY_WEIGHT);

    // create residual sub-plot
    final NumberAxis residualAxis = new NumberAxis(RESIDUAL_AXIS_LABEL);
    final XYSplineRenderer residualRenderer = new XYSplineRenderer();
    residualRenderer.setSeriesPaint(0, RESIDUAL_COLOR);
    residualRenderer.setSeriesLinesVisible(0, false);
    residualRenderer.setSeriesShape(0, new Ellipse2D.Float(-1.0f, -1.0f, 2.0f, 2.0f));

    final XYPlot residualSubPlot = new XYPlot(_residualDataset, null, residualAxis, residualRenderer);
    residualSubPlot.setDomainCrosshairVisible(true);
    residualSubPlot.setRangeCrosshairVisible(true);
    residualSubPlot.setFixedLegendItems(null);

    // add residual sub-plot to parent
    parent.add(residualSubPlot, RESIDUAL_WEIGHT);

    // now make the top level JFreeChart
    final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, parent, true);
    chart.removeLegend();

    return chart;
}