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

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

Introduction

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

Prototype

public void setInverted(boolean flag) 

Source Link

Document

Sets a flag that controls the direction of values on the axis, and notifies registered listeners that the axis has changed.

Usage

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

private static JFreeChart createChart(XYZDataset xyzdataset) {
    NumberAxis numberaxis = new NumberAxis("X");
    numberaxis.setLowerMargin(0.0D);//  w  w w. j ava  2 s  .co m
    numberaxis.setUpperMargin(0.0D);
    NumberAxis numberaxis1 = new NumberAxis("Y");
    numberaxis1.setAutoRangeIncludesZero(false);
    numberaxis1.setInverted(true);
    numberaxis1.setLowerMargin(0.0D);
    numberaxis1.setUpperMargin(0.0D);
    numberaxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYBlockRenderer xyblockrenderer = new XYBlockRenderer();
    LookupPaintScale lookuppaintscale = new LookupPaintScale(0.5D, 3.5D, Color.black);
    lookuppaintscale.add(0.5D, Color.green);
    lookuppaintscale.add(1.5D, Color.orange);
    lookuppaintscale.add(2.5D, Color.red);
    xyblockrenderer.setPaintScale(lookuppaintscale);
    XYPlot xyplot = new XYPlot(xyzdataset, numberaxis, numberaxis1, xyblockrenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setForegroundAlpha(0.66F);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    JFreeChart jfreechart = new JFreeChart("XYBlockChartDemo3", xyplot);
    jfreechart.removeLegend();
    jfreechart.setBackgroundPaint(Color.white);
    SymbolAxis symbolaxis = new SymbolAxis(null, new String[] { "", "OK", "Uncertain", "Bad" });
    symbolaxis.setRange(0.5D, 3.5D);
    symbolaxis.setPlot(new PiePlot());
    symbolaxis.setGridBandsVisible(false);
    PaintScaleLegend paintscalelegend = new PaintScaleLegend(lookuppaintscale, symbolaxis);
    paintscalelegend.setAxisOffset(5D);
    paintscalelegend.setPosition(RectangleEdge.BOTTOM);
    paintscalelegend.setMargin(new RectangleInsets(5D, 5D, 5D, 5D));
    jfreechart.addSubtitle(paintscalelegend);
    return jfreechart;
}

From source file:projects.tgas.exec.HrDiagram.java

/**
 * Plot the HR diagram chart from the given data.
 * @param series// w  w w . jav  a2s  .c om
 *    A {@link XYSeries} containing the HR diagram data.
 * @return
 *    A {@link JFreeChart} containing the plot.
 */
private static JFreeChart getHrChart(XYSeries series) {

    XYSeriesCollection hrData = new XYSeriesCollection();
    hrData.addSeries(series);

    // Set up the renderer
    XYLineAndShapeRenderer hrRenderer = new XYLineAndShapeRenderer();

    hrRenderer.setSeriesLinesVisible(0, false);
    hrRenderer.setSeriesShapesVisible(0, true);
    hrRenderer.setSeriesShape(0, new Ellipse2D.Double(-0.5, -0.5, 1, 1));

    // Configure axes
    NumberAxis xAxis = new NumberAxis("B - V [mag]");
    xAxis.setRange(-0.5, 2.25);

    NumberAxis yAxis = new NumberAxis("G [mag]");
    yAxis.setInverted(true);
    yAxis.setRange(-5, 13);

    // Configure plot
    XYPlot xyplot = new XYPlot(hrData, xAxis, yAxis, hrRenderer);
    xyplot.setBackgroundPaint(Color.white);

    JFreeChart hrChart = new JFreeChart("HR diagram of TGAS stars", xyplot);
    hrChart.removeLegend();
    hrChart.setBackgroundPaint(Color.white);

    return hrChart;
}

From source file:projects.hip.exec.HrDiagram.java

/**
 * Plot the HR diagram chart from the given data.
 * @param series//from  w w  w.ja v a  2  s .  c  om
 *    A {@link XYSeries} containing the HR diagram data.
 * @return
 *    A {@link JFreeChart} containing the plot.
 */
private static JFreeChart getHrChart(XYSeries series) {

    XYSeriesCollection hrData = new XYSeriesCollection();
    hrData.addSeries(series);

    // Set up the renderer
    XYLineAndShapeRenderer hrRenderer = new XYLineAndShapeRenderer();

    hrRenderer.setSeriesLinesVisible(0, false);
    hrRenderer.setSeriesShapesVisible(0, true);
    hrRenderer.setSeriesShape(0, new Ellipse2D.Double(-0.5, -0.5, 1, 1));

    // Configure axes
    NumberAxis xAxis = new NumberAxis("B - V [mag]");
    xAxis.setRange(-0.5, 2.25);

    NumberAxis yAxis = new NumberAxis("H [mag]");
    yAxis.setInverted(true);
    yAxis.setRange(-5, 13);

    // Configure plot
    XYPlot xyplot = new XYPlot(hrData, xAxis, yAxis, hrRenderer);
    xyplot.setBackgroundPaint(Color.white);

    JFreeChart hrChart = new JFreeChart("HR diagram of Hipparcos stars", xyplot);
    hrChart.removeLegend();
    hrChart.setBackgroundPaint(Color.white);

    return hrChart;
}

From source file:MWC.GUI.JFreeChart.DepthFormatter.java

public void format(final XYPlot thePlot) {
    final NumberAxis theAxis = (NumberAxis) thePlot.getRangeAxis();
    theAxis.setInverted(true);
}

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

/**
 * A demonstration application showing an XY series containing a null value.
 *
 * @param title  the frame title./*  w  w  w .  j av a2s .co m*/
 */
public WaterTemperatureDemo(final String title) {

    super(title);
    final XYDataset dataset = createDataset();

    final NumberAxis rangeAxis = new NumberAxis("Temperature");
    rangeAxis.setRange(-0.55, -0.15);

    final NumberAxis domainAxis = new NumberAxis("Depth");
    domainAxis.setInverted(true);
    domainAxis.setRange(0.0, 35.0);
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final XYItemRenderer renderer = new StandardXYItemRenderer();

    final XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    final JFreeChart chart = new JFreeChart("Water Temperature By Depth", plot);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:org.btrg.df.betterologist.swingui.ProjectJobSchedulingPanel.java

private JFreeChart createChart(Schedule schedule) {
    YIntervalSeriesCollection seriesCollection = new YIntervalSeriesCollection();
    Map<Project, YIntervalSeries> projectSeriesMap = new LinkedHashMap<Project, YIntervalSeries>(
            schedule.getProjectList().size());
    YIntervalRenderer renderer = new YIntervalRenderer();
    int maximumEndDate = 0;
    int seriesIndex = 0;
    for (Project project : schedule.getProjectList()) {
        YIntervalSeries projectSeries = new YIntervalSeries(project.getLabel());
        seriesCollection.addSeries(projectSeries);
        projectSeriesMap.put(project, projectSeries);
        renderer.setSeriesShape(seriesIndex, new Rectangle());
        renderer.setSeriesStroke(seriesIndex, new BasicStroke(3.0f));
        seriesIndex++;/*from ww w . j a va 2s. c om*/
    }
    for (Allocation allocation : schedule.getAllocationList()) {
        int startDate = allocation.getStartDate();
        int endDate = allocation.getEndDate();
        YIntervalSeries projectSeries = projectSeriesMap.get(allocation.getProject());
        projectSeries.add(allocation.getId(), (startDate + endDate) / 2.0, startDate, endDate);
        maximumEndDate = Math.max(maximumEndDate, endDate);
    }
    NumberAxis domainAxis = new NumberAxis("Job");
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setRange(-0.5, schedule.getAllocationList().size() - 0.5);
    domainAxis.setInverted(true);
    NumberAxis rangeAxis = new NumberAxis("Day (start to end date)");
    rangeAxis.setRange(-0.5, maximumEndDate + 0.5);
    XYPlot plot = new XYPlot(seriesCollection, domainAxis, rangeAxis, renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    return new JFreeChart("Project Job Scheduling", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}

From source file:com.itemanalysis.jmetrik.graph.itemmap.ItemMapPanel.java

public void setGraph() {
    HistogramChartDataset personDataset = null;
    HistogramChartDataset itemData = null;

    try {/*from   ww w . j a  v a  2s  .com*/
        //get titles
        String chartTitle = command.getFreeOption("title").getString();
        String chartSubtitle = command.getFreeOption("subtitle").getString();
        PlotOrientation itemMapOrientation = PlotOrientation.HORIZONTAL;

        //create common x-axis
        NumberAxis domainAxis = new NumberAxis();
        domainAxis.setLabel("Logits");

        //create histogram
        personDataset = new HistogramChartDataset();
        ValueAxis rangeAxis = new NumberAxis("Person Density");
        if (itemMapOrientation == PlotOrientation.HORIZONTAL)
            rangeAxis.setInverted(true);
        XYBarRenderer renderer = new XYBarRenderer();
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
        renderer.setURLGenerator(new StandardXYURLGenerator());
        renderer.setDrawBarOutline(true);
        renderer.setShadowVisible(false);
        XYPlot personPlot = new XYPlot(personDataset, null, rangeAxis, renderer);
        personPlot.setOrientation(PlotOrientation.HORIZONTAL);

        //create scatterplot of item difficulty
        itemData = new HistogramChartDataset();
        NumberAxis itemRangeAxis = new NumberAxis("Item Frequency");
        if (itemMapOrientation == PlotOrientation.VERTICAL) {
            itemRangeAxis.setInverted(true);
        }

        XYBarRenderer itemRenderer = new XYBarRenderer();
        itemRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
        itemRenderer.setURLGenerator(new StandardXYURLGenerator());
        itemRenderer.setDrawBarOutline(true);
        itemRenderer.setShadowVisible(false);
        XYPlot itemPlot = new XYPlot(itemData, null, itemRangeAxis, itemRenderer);
        itemPlot.setOrientation(PlotOrientation.HORIZONTAL);

        //combine the two charts
        CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis);
        cplot.add(personPlot, 3);
        cplot.add(itemPlot, 2);
        cplot.setGap(8.0);
        cplot.setDomainGridlinePaint(Color.white);
        cplot.setDomainGridlinesVisible(true);
        cplot.setOrientation(itemMapOrientation);

        //            //next four lines are temp setting for book
        //            //these four lines will create a histogram with white bars so it appears as just the bar outline
        //            renderer.setBarPainter(new StandardXYBarPainter());
        //            renderer.setSeriesPaint(0, Color.white);
        //            itemRenderer.setBarPainter(new StandardXYBarPainter());
        //            itemRenderer.setSeriesPaint(0, Color.white);

        chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, cplot, false);
        chart.setBackgroundPaint(Color.white);
        if (chartSubtitle != null && !"".equals(chartSubtitle)) {
            chart.addSubtitle(new TextTitle(chartSubtitle));
        }

        ChartPanel panel = new ChartPanel(chart);
        panel.getPopupMenu().addSeparator();
        this.addJpgMenuItem(this, panel.getPopupMenu());
        panel.setPreferredSize(new Dimension(width, height));

        //            //temp setting for book
        //            this.addLocalEPSMenuItem(this, panel.getPopupMenu(), chart);//remove this line for public release versions

        chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0));
        this.setBackground(Color.WHITE);
        this.add(panel);
    } catch (IllegalArgumentException ex) {
        logger.fatal(ex.getMessage(), ex);
        this.firePropertyChange("error", "", "Error - Check log for details.");
    }

}

From source file:projects.upc.exec.HrDiagram.java

/**
 * Update the {@link HrDiagram#chartPanel}.
 *//*  w  ww  .  j a v  a2  s  .co  m*/
private void updateChart() {

    XYSeries series = new XYSeries("UPC HR diagram");

    for (Entry<UpcStar, SsaCrossMatch> xm : starsToPlot.entrySet()) {

        UpcStar upcStar = xm.getKey();
        SsaCrossMatch ssa = xm.getValue();

        // Get the SSA colours of the UPC star
        double b = ssa.ssaB;
        double r2 = ssa.ssaR2;
        //         double i = ssa.ssaI;

        // Use the parallax to correct the apparent magnitude to absolute magnitude.

        // Extract the parallax and error to use
        double p = (useHip && upcStar.isHipparcosStar()) ? upcStar.srcPi : upcStar.absPi;
        double sigma_p = (useHip && upcStar.isHipparcosStar()) ? upcStar.srcPiErr : upcStar.absPiErr;

        // Filter on the fractional parallax error
        double f = sigma_p / p;
        if (f > fMax) {
            continue;
        }

        // Correct to arcseconds
        p /= 1000;
        sigma_p /= 1000;

        // Get the distance
        double d = DistanceFromParallax.getDistance(p, sigma_p, method);
        // Filter & convert to absolute magnitude
        if (d > 0 && !Double.isInfinite(d)) {
            double B = MagnitudeUtils.getAbsoluteMagnitude(d, b);
            series.add(b - r2, B);
        }
    }

    XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(series);

    // Set up the renderer
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesShape(0, new Ellipse2D.Double(-0.5, -0.5, 1, 1));

    // Configure axes
    NumberAxis xAxis = new NumberAxis("B - R [mag]");
    xAxis.setRange(-1.0, 3.5);

    NumberAxis yAxis = new NumberAxis("B [mag]");
    yAxis.setInverted(true);
    yAxis.setRange(-5, 15);

    // Configure plot
    XYPlot xyplot = new XYPlot(data, xAxis, yAxis, renderer);
    xyplot.setBackgroundPaint(Color.white);

    JFreeChart chart = new JFreeChart("HR diagram of UPC stars with SSA cross-matches", xyplot);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);

    if (chartPanel == null) {
        // Branch is used on initialisation
        chartPanel = new ChartPanel(chart);
    } else {
        chartPanel.setChart(chart);
    }

}

From source file:com.bwc.ora.views.LrpDisplayFrame.java

private void setChart(LrpSeries series) {
    lrpSeries = series.getLrpSeries();//ww  w.  j a v  a2 s  .  c o  m
    maximaSeries = series.getMaximaSeries();
    hiddenMaximaSeries = series.getHiddenMaximaSeries();
    graphData = new XYSeriesCollection();

    //add series data to graph
    graphData.addSeries(lrpSeries);
    graphData.addSeries(maximaSeries);
    graphData.addSeries(hiddenMaximaSeries);
    series.getFwhmSeries().forEach(graphData::addSeries);

    //create the chart for displaying the data
    JFreeChart chart = ChartFactory.createXYLineChart("LRP", "Pixel Height", "Reflectivity", graphData,
            PlotOrientation.HORIZONTAL, true, true, false);
    chartPanel.setChart(chart);

    //create a custom renderer to control the display of each series
    //set draw properties for the LRP data
    HighlightXYRenderer renderer = new HighlightXYRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesPaint(0, Color.RED);

    //set draw properties for the maxima data
    renderer.setDrawOutlines(true);
    renderer.setUseOutlinePaint(true);
    renderer.setUseFillPaint(true);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShapesVisible(1, true);
    renderer.setSeriesShapesFilled(1, true);
    renderer.setSeriesFillPaint(1, Color.BLUE);
    renderer.setSeriesShape(1, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));

    //set draw properties for the hidden maxima data
    renderer.setSeriesLinesVisible(2, false);
    renderer.setSeriesShapesVisible(2, true);
    renderer.setSeriesShapesFilled(2, true);
    renderer.setSeriesFillPaint(2, Color.MAGENTA);
    renderer.setSeriesShape(2, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0));

    //set draw properties for each of the full-width half-max lines
    for (int i = 3; i < series.getFwhmSeries().size() + 3; i++) {
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesShapesVisible(i, false);
        renderer.setSeriesPaint(i, Color.BLACK);
        renderer.setSeriesVisibleInLegend(i, false, false);
    }

    chart.getXYPlot().setRenderer(renderer);

    //add listener for highlighting points when hovered over
    if (mouseMovementListener != null) {
        chartPanel.removeChartMouseListener(mouseMovementListener);
    }
    mouseMovementListener = getMovementChartMouseListener(renderer);
    chartPanel.addChartMouseListener(mouseMovementListener);

    //mark the Domain (which appears as the range in a horizontal graph) 
    // axis as inverted so LRP matches with OCT
    ValueAxis domainAxis = chart.getXYPlot().getDomainAxis();
    if (domainAxis instanceof NumberAxis) {
        NumberAxis axis = (NumberAxis) domainAxis;
        axis.setInverted(true);
    }

    //disable the need for the range of the chart to include zero
    ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis();
    if (rangeAxis instanceof NumberAxis) {
        NumberAxis axis = (NumberAxis) rangeAxis;
        axis.setAutoRangeIncludesZero(false);
    }

    //if there were any previous annotations to the LRP add them to the chart
    lrps.getSelectedValue().getAnnotations().forEach(chart.getXYPlot()::addAnnotation);
}

From source file:org.esa.beam.smos.visat.GridPointBtDataFlagmatrixToolView.java

private NumberAxis createRangeAxis(String[] flagNames) {
    final NumberAxis axis = new SymbolAxis(null, flagNames);
    axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    axis.setAutoRangeIncludesZero(false);
    axis.setLowerMargin(0.0);//from w  w w .j a va 2  s .  c om
    axis.setUpperMargin(0.0);
    axis.setInverted(true);

    return axis;
}