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:loadmaprenderer.ResultDisplayChart.java

private JFreeChart makeChart(XYDataset dataset, String chartTitle, String dataTitle) {
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, "Year", dataTitle, dataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot plot = chart.getXYPlot();/*from  w  w w. ja  v  a 2 s .co  m*/
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.BLUE);
    plot.setRangeGridlinePaint(Color.BLUE);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRange(true);
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRange(true);
    Double range = dataLine.getMaxY() - dataLine.getMinY();
    if (Math.abs(range) < 0.1)
        range = dataLine.getMaxY();
    rangeAxis.setRange(dataLine.getMinY() - range * 0.1, dataLine.getMaxY() + range * 0.1);
    return chart;
}

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

public MMPGraph(XYSeries series) {
    super();//from w  w  w .  j a  v a 2  s. com

    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.gvsig.remotesensing.profiles.gui.ZProfileOptionsPanel.java

public GraphicChartPanel getJPanelChart() {
    jPanelChart.cleanChart();//from  w  w w . ja  v a2s.  c o m
    XYPlot plot = jPanelChart.getChart().getChart().getXYPlot();
    NumberAxis domainAxis = new NumberAxis(PluginServices.getText(this, "bandas"));
    domainAxis.setRange(1, getGrid().getBandCount());
    domainAxis.setTickUnit(new NumberTickUnit(1.0));
    plot.setDomainAxis(domainAxis);
    return jPanelChart;
}

From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.KaplanMeierPlot.java

private void createChart(XYDataset dataset) {
    //Create the chart, dropping in the data set
    JFreeChart chart = ChartFactory.createXYLineChart("", "Days in Study", "Probability of Survival", dataset,
            PlotOrientation.VERTICAL, false, //legend
            true, //tooltips
            false//urls
    );/*from   w  ww. j  a  v a  2  s  . co  m*/
    LegendTitle legend = chart.getLegend();
    XYPlot plot = (XYPlot) chart.getPlot();
    /********************************************************
     * IMPORTANT:
     * Ideally I would create the actual Renderer settings for
     * the at the time I start to march through the 
     * KaplanMeierPlotPointSeriesSets, adding them to the actual
     * Data Set that is going to be going into the Chart plotter.
     * But you have no idea how they are going to be sitting in
     * the Plot dataset so there is no guarantee that setting the
     * renderer based on a supposed index will actually work. In fact
     * it didn't work when I wrote this.
     * 
     */
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < finalDataCollection.getSeriesCount(); i++) {
        KaplanMeierPlotPointSeries kmSeries = (KaplanMeierPlotPointSeries) finalDataCollection.getSeries(i);
        if (kmSeries.getType() == SeriesType.CENSOR) {
            renderer.setSeriesLinesVisible(i, false);
            renderer.setSeriesShapesVisible(i, true);
        } else if (kmSeries.getType() == SeriesType.PROBABILITY) {
            renderer.setSeriesLinesVisible(i, true);
            renderer.setSeriesShapesVisible(i, false);

        } else {
            //don't show this set as it is not a known type
            renderer.setSeriesLinesVisible(i, false);
            renderer.setSeriesShapesVisible(i, false);
        }
        renderer.setSeriesPaint(i, getKMSetColor(kmSeries.getKey(), kmSeries.getType()), true);
    }

    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setDefaultEntityRadius(6);
    plot.setRenderer(renderer);
    //change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.
    rangeAxis.setAutoRange(true);
    rangeAxis.setRange(0.0, 1.0);
    kmChart = chart;
}

From source file:org.nees.rpi.vis.ui.ProfilePlotFrame.java

public void plot() {
    Collections.sort(series);//from  w w w.j  a va2  s .  c  o  m

    XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();
    NumberAxis axis = (NumberAxis) plot.getDomainAxis();
    axis.setRange(rangeMin, rangeMax);

    int timeIndex = 0;
    plotTime(timeIndex);
}

From source file:org.optaplanner.examples.cheaptime.swingui.CheapTimePanel.java

private XYPlot createTaskAssignmentPlot(TangoColorFactory tangoColorFactory, CheapTimeSolution solution) {
    OHLCSeriesCollection seriesCollection = new OHLCSeriesCollection();
    Map<Machine, OHLCSeries> machineSeriesMap = new LinkedHashMap<Machine, OHLCSeries>(
            solution.getMachineList().size());
    HighLowRenderer renderer = new HighLowRenderer();
    renderer.setTickLength(0.0);//from w w  w  .  j a v  a  2s . com
    int seriesIndex = 0;
    OHLCSeries unassignedProjectSeries = new OHLCSeries("Unassigned");
    seriesCollection.addSeries(unassignedProjectSeries);
    machineSeriesMap.put(null, unassignedProjectSeries);
    renderer.setSeriesStroke(seriesIndex, new BasicStroke(3.0f));
    renderer.setSeriesPaint(seriesIndex, TangoColorFactory.SCARLET_1);
    seriesIndex++;
    for (Machine machine : solution.getMachineList()) {
        OHLCSeries machineSeries = new OHLCSeries(machine.getLabel());
        seriesCollection.addSeries(machineSeries);
        machineSeriesMap.put(machine, machineSeries);
        renderer.setSeriesStroke(seriesIndex, new BasicStroke(3.0f));
        renderer.setSeriesPaint(seriesIndex, tangoColorFactory.pickColor(machine));
        seriesIndex++;
    }
    List<TaskAssignment> taskAssignmentList = new ArrayList<TaskAssignment>(solution.getTaskAssignmentList());
    Collections.sort(taskAssignmentList,
            groupByMachineCheckBox.isSelected() ? groupByMachineTaskAssignmentComparator
                    : stableTaskAssignmentComparator);
    int pixelIndex = 0;
    for (TaskAssignment taskAssignment : taskAssignmentList) {
        Task task = taskAssignment.getTask();
        Integer startPeriod = taskAssignment.getStartPeriod();
        Integer endPeriod = taskAssignment.getEndPeriod();
        if (startPeriod == null) {
            startPeriod = task.getStartPeriodRangeFrom();
            endPeriod = startPeriod + task.getDuration();
        }
        OHLCSeries machineSeries = machineSeriesMap.get(taskAssignment.getMachine());
        machineSeries.add(new FixedMillisecond(pixelIndex), task.getStartPeriodRangeFrom(), startPeriod,
                endPeriod, task.getStartPeriodRangeTo() + task.getDuration());
        pixelIndex++;
    }
    NumberAxis domainAxis = new NumberAxis("Task");
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setRange(-0.5, taskAssignmentList.size() - 0.5);
    domainAxis.setInverted(true);
    return new XYPlot(seriesCollection, domainAxis, null, renderer);
}

From source file:com.att.aro.ui.view.overviewtab.FileTypesChartPanel.java

private JFreeChart initializeChart() {
    JFreeChart chart = ChartFactory.createBarChart(
            ResourceBundleHelper.getMessageString("chart.filetype.title"), null,
            ResourceBundleHelper.getMessageString("simple.percent"), null, PlotOrientation.HORIZONTAL, false,
            false, false);//  www.  j  a va 2 s.co  m

    //chart.setBackgroundPaint(fileTypePanel.getBackground());
    chart.setBackgroundPaint(this.getBackground());
    chart.getTitle().setFont(AROUIManager.HEADER_FONT);

    this.cPlot = chart.getCategoryPlot();
    cPlot.setBackgroundPaint(Color.white);
    cPlot.setDomainGridlinePaint(Color.gray);
    cPlot.setRangeGridlinePaint(Color.gray);
    cPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    CategoryAxis domainAxis = cPlot.getDomainAxis();
    domainAxis.setMaximumCategoryLabelWidthRatio(.5f);
    domainAxis.setLabelFont(AROUIManager.LABEL_FONT);
    domainAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    NumberAxis rangeAxis = (NumberAxis) cPlot.getRangeAxis();
    rangeAxis.setRange(0.0, 100.0);
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setLabelFont(AROUIManager.LABEL_FONT);
    rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    BarRenderer renderer = new StackedBarRenderer();
    renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setBaseItemLabelGenerator(new PercentLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelPaint(Color.black);

    // Make second bar in stack invisible
    renderer.setSeriesItemLabelsVisible(1, false);
    renderer.setSeriesPaint(1, new Color(0, 0, 0, 0));

    renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {

            FileTypeSummary summary = fileTypeContent.get(column);

            return MessageFormat.format(ResourceBundleHelper.getMessageString("chart.filetype.tooltip"),
                    NumberFormat.getIntegerInstance().format(summary.getBytes()));
        }
    });

    ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3,
            TextAnchor.CENTER_RIGHT);
    renderer.setBasePositiveItemLabelPosition(insideItemlabelposition);

    ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3,
            TextAnchor.CENTER_LEFT);
    renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition);

    BarPainter painter = new StandardBarPainter();
    renderer.setBarPainter(painter);
    renderer.setShadowVisible(false);
    renderer.setMaximumBarWidth(0.1);

    cPlot.setRenderer(renderer);
    cPlot.getDomainAxis().setMaximumCategoryLabelLines(2);

    return chart;
}

From source file:ec.ui.view.AutoCorrelationsView.java

protected void onDataChange() {
    chartPanel.getChart().setTitle(ACKind.Normal == kind ? "Autocorrelations" : "Partial autocorrelations");
    NumberAxis domainAxis = (NumberAxis) chartPanel.getChart().getXYPlot().getDomainAxis();
    domainAxis.setRange(0, length);
    domainAxis.setTickUnit(new NumberTickUnit(length / 6));

    if (ac == DEFAULT_AUTO_CORRELATIONS) {
        chartPanel.getChart().getXYPlot().setDataset(Charts.emptyXYDataset());
    } else {/*from   w ww. j  a  v  a 2s. co  m*/
        ac.setCorrectedForMean(meanCorrection);
        ac.setKMax(length);

        double[] vals = ACKind.Normal == kind ? ac.getAC() : ac.getPAC();
        XYSeries series = new XYSeries("");
        for (int i = 0; i < vals.length; ++i) {
            series.add(i + 1, vals[i]);
        }

        XYPlot plot = chartPanel.getChart().getXYPlot();
        plot.clearRangeMarkers();
        plot.setDataset(new XYBarDataset(new XYSeriesCollection(series), 1));

        double z = 2.0d / Math
                .sqrt(ac.getUnderlyingData().getDataCount() - ac.getUnderlyingData().getMissingValuesCount());
        for (double o : new double[] { z, -z }) {
            ValueMarker marker = new ValueMarker(o);
            marker.setStroke(MARKER_STROKE);
            marker.setAlpha(MARKER_ALPHA);
            plot.addRangeMarker(marker);
        }

        onColorSchemeChange();
    }
}

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

/**
 * Update the {@link HrDiagram#chartPanel}.
 *//*from  w  w w.  j ava2s . c o  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:fungus.PeerRatioChartFrame.java

public PeerRatioChartFrame(String prefix) {
    simulationCycles = Configuration.getDouble(PAR_SIMULATION_CYCLES);
    this.setTitle("MycoNet Statistics Chart");
    graph = JungGraphObserver.getGraph();

    //data.add(-1,0);
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.setAutoWidth(false);//from w ww .  jav  a 2s. c o m
    dataset.setIntervalWidth(simulationCycles);

    //averageUtilizationData = new XYSeries("Average Utilization");
    //dataset.addSeries(averageUtilizationData);
    //averageStableUtilizationData = new XYSeries("Avg Stable Util");
    //dataset.addSeries(averageStableUtilizationData);
    bulwarkRatioData = new XYSeries("Bulwark Ratio");
    dataset.addSeries(bulwarkRatioData);
    biomassRatioData = new XYSeries("Biomass Ratio");
    dataset.addSeries(biomassRatioData);
    hyphaRatioData = new XYSeries("Hypha Ratio");
    dataset.addSeries(hyphaRatioData);
    // stableHyphaRatioData = new XYSeries("Stable Hypha Ratio");
    // dataset.addSeries(stableHyphaRatioData);

    //XYSeriesCollection dataset;

    JFreeChart peerRatioChart = ChartFactory.createXYLineChart("Bulwark Metrics", "Cycle", "Peer State Ratio",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    ChartPanel peerRatioChartPanel = new ChartPanel(peerRatioChart);

    XYPlot xyplot = peerRatioChart.getXYPlot();

    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setRange(0, 1);

    //chart.setBackgroundPaint(Color.white);
    //XYPlot plot = chart.getXYPlot();

    //        BufferedImage chartImage = chart.createBufferedImage(500,300);
    //        chartLabel = new JLabel();
    //chartLabel.setIcon(new ImageIcon(chartImage));

    Container contentPane = getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
    JPanel labelPane = new JPanel();
    labelPane.setLayout(new GridLayout(1, 1));
    //chartPane.setPreferredSize(new java.awt.Dimension(500, 300));
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));

    ////contentPane.add(labelPane,BorderLayout.PAGE_START);
    //contentPane.add(Box.createRigidArea(new Dimension(0,5)));
    contentPane.add(peerRatioChartPanel, BorderLayout.CENTER);
    //contentPane.add(Box.createRigidArea(new Dimension(0,5)));
    ////contentPane.add(buttonPane, BorderLayout.PAGE_END);

    //data = node.getHyphaData();
    //link = node.getHyphaLink();
    //mycocast = node.getMycoCast();

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    //chartPanel.add(chartLabel);

    /*JButton updateButton = new JButton("Refresh");
      ActionListener updater = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      refreshData();
      }
      };
      updateButton.addActionListener(updater);
            
      JButton closeButton = new JButton("Close");
      ActionListener closer = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      closeFrame();
      }
      };
      closeButton.addActionListener(closer);
            
      buttonPane.add(Box.createHorizontalGlue());
      buttonPane.add(updateButton);
      buttonPane.add(Box.createRigidArea(new Dimension(5,0)));
      buttonPane.add(closeButton);
      refreshData();
    */

    //JungGraphObserver.addChangeListener(this);

    this.pack();
    this.setVisible(true);
}