Example usage for org.jfree.chart.axis ValueAxis getLowerBound

List of usage examples for org.jfree.chart.axis ValueAxis getLowerBound

Introduction

In this page you can find the example usage for org.jfree.chart.axis ValueAxis getLowerBound.

Prototype

public double getLowerBound() 

Source Link

Document

Returns the lower bound of the axis range.

Usage

From source file:RDGraphGenerator.java

/**
 * Creates a sample chart.//from   w w  w. j  ava 2 s.  co m
 *
 * @param dataset  the dataset for the chart.
 *
 * @return A sample chart.
 */
private JFreeChart createDistChart(String riderID) {

    String riderName = (String) riders.get(riderID);
    final JFreeChart chart = ChartFactory.createStackedBarChart(riderName + "'s Distances", // chart title
            "Month", // domain axis label
            mainDist, // range axis label
            (CategoryDataset) riderDistances.get(riderID), // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // legend
            true, // tooltips
            false // urls
    );

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("0", "G1");
    map.mapKeyToGroup("1", "G1");
    map.mapKeyToGroup("2", "G1");
    map.mapKeyToGroup("3", "G1");
    renderer.setSeriesToGroupMap(map);

    renderer.setItemMargin(0.0);
    Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f,
            new Color(0x88, 0x88, 0xFF));
    renderer.setSeriesPaint(0, p1);

    Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0x88, 0xFF, 0x88));
    renderer.setSeriesPaint(1, p2);

    Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0x88, 0x88));
    renderer.setSeriesPaint(2, p3);

    Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0xFF, 0x88));
    renderer.setSeriesPaint(3, p4);
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRenderer(renderer);
    plot.setFixedLegendItems(createLegendItems());
    ValueAxis va = (ValueAxis) plot.getRangeAxis();
    ValueAxis ova = null;
    try {
        ova = (ValueAxis) va.clone();
    } catch (CloneNotSupportedException cnse) {
    }
    ova.setLabel(secondaryDist);
    ova.setLowerBound(va.getLowerBound() * unitConversion);
    ova.setUpperBound(va.getUpperBound() * unitConversion);
    plot.setRangeAxis(1, ova);
    plot.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT);
    CategoryAxis ca = plot.getDomainAxis();
    ca.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    //Make around the chart transparent.
    chart.setBackgroundPaint(null);
    return chart;

}

From source file:org.squale.squaleweb.util.graph.ScatterMaker.java

/**
 * Construit (ou reconstruit) le diagramme puis le retourne
 * //from  ww  w.  j ava2 s.c o  m
 * @return le diagramme JFreeChart.
 */
protected JFreeChart getChart() {
    LOG.debug(WebMessages.getString("method.entry"));
    JFreeChart retChart = super.getChart();
    if (null == retChart) {
        // Gnration du Scatterplot
        retChart = ChartFactory.createScatterPlot(mTitle, mXLabel, mYLabel, mDataSet, PlotOrientation.VERTICAL,
                mShowLegend, false, false);
        ValueAxis domainAxis = retChart.getXYPlot().getDomainAxis();
        ValueAxis rangeAxis = retChart.getXYPlot().getRangeAxis();

        // Dtermination des bornes en abscisse et en ordonne
        double maxDomain = Math.max(domainAxis.getUpperBound(),
                DEFAULT_VERTICAL_AXIS_POS + DEFAULT_AXIS_MARGIN);
        double minDomain = Math.min(domainAxis.getLowerBound(),
                DEFAULT_VERTICAL_AXIS_POS - DEFAULT_AXIS_MARGIN);
        double maxRange = Math.max(rangeAxis.getUpperBound(),
                DEFAULT_HORIZONTAL_AXIS_POS + DEFAULT_AXIS_MARGIN);
        double minRange = Math.min(rangeAxis.getLowerBound(),
                DEFAULT_HORIZONTAL_AXIS_POS - DEFAULT_AXIS_MARGIN);

        // Mise  l'chelle logarithmique des axes
        LogarithmicAxis newDomainAxis = new LogarithmicAxis(domainAxis.getLabel());
        LogarithmicAxis newRangeAxis = new LogarithmicAxis(rangeAxis.getLabel());

        // Affectation des bornes en abscisse et en ordonne
        newDomainAxis.setLowerBound(minDomain);
        newDomainAxis.setUpperBound(maxDomain);
        newRangeAxis.setLowerBound(minRange);
        newRangeAxis.setUpperBound(maxRange);
        retChart.getXYPlot().setDomainAxis(newDomainAxis);
        retChart.getXYPlot().setRangeAxis(newRangeAxis);

        // Le point a une taille fixe
        Shape shape = new Rectangle(DEFAULT_POINT_SIZE, DEFAULT_POINT_SIZE);
        retChart.getXYPlot().getRenderer().setShape(shape);

        // Annotations
        XYLineAnnotation horizontalAxis = new XYLineAnnotation(minDomain, DEFAULT_HORIZONTAL_AXIS_POS,
                maxDomain, DEFAULT_HORIZONTAL_AXIS_POS);
        XYLineAnnotation verticalAxis = new XYLineAnnotation(DEFAULT_VERTICAL_AXIS_POS, minRange,
                DEFAULT_VERTICAL_AXIS_POS, maxRange);
        retChart.getXYPlot().addAnnotation(horizontalAxis);
        retChart.getXYPlot().addAnnotation(verticalAxis);

        super.setChart(retChart);
    }
    LOG.debug(WebMessages.getString("method.exit"));
    return retChart;
}

From source file:org.openfaces.component.chart.impl.plots.XYPlotAdapter.java

private void renderItems(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info,
        CrosshairState crosshairState, XYDataset xyDataset, ValueAxis xValueAxis, ValueAxis yValueAxis,
        XYItemRenderer xyItemRenderer, XYItemRendererState state, int totalRendererPasses, int seriesIndex) {
    for (int currentPassIndex = 0; currentPassIndex < totalRendererPasses; currentPassIndex++) {
        if (xyDataset.getItemCount(seriesIndex) == 0) {
            return;
        }/*from w  w w .j  ava  2  s.com*/

        int firstItemIndex = 0;
        int lastItemIndex = xyDataset.getItemCount(seriesIndex) - 1;

        if (state.getProcessVisibleItemsOnly()) {
            final double xLowerBound = xValueAxis.getLowerBound();
            final double xUpperBound = xValueAxis.getUpperBound();
            int[] itemBounds = RendererUtilities.findLiveItems(xyDataset, seriesIndex, xLowerBound,
                    xUpperBound);
            firstItemIndex = itemBounds[0] - 1;
            if (firstItemIndex < 0) {
                firstItemIndex = 0;
            }
            final int lastBoundaryIndex = itemBounds[1] + 1;
            if (lastBoundaryIndex < lastItemIndex) {
                lastItemIndex = lastBoundaryIndex;
            }
        }

        state.startSeriesPass(xyDataset, seriesIndex, firstItemIndex, lastItemIndex, currentPassIndex,
                totalRendererPasses);

        for (int item = firstItemIndex; item <= lastItemIndex; item++) {
            xyItemRenderer.drawItem(g2, state, dataArea, info, this, xValueAxis, yValueAxis, xyDataset,
                    seriesIndex, item, crosshairState, currentPassIndex);
        }

        state.endSeriesPass(xyDataset, seriesIndex, firstItemIndex, lastItemIndex, currentPassIndex,
                totalRendererPasses);
    }
}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

public void chartChanged(ChartChangeEvent event) {
    try {/*www  . ja va  2  s. c o m*/
        if (event.getChart() == null) {
            return;
        }

        BoundedRangeModel scrollBarModel = this.chartScrollBar.getModel();
        if (scrollBarModel == null) {
            return;
        }

        boolean chartIsZoomed = false;

        Plot plot = event.getChart().getPlot();
        if (plot instanceof XYPlot) {
            XYPlot hvp = (XYPlot) plot;
            ValueAxis xAxis = hvp.getDomainAxis();
            Range xAxisRange = xAxis.getRange();

            // avoid recursion
            scrollBarModel.removeChangeListener(this);

            int low = (int) (xAxisRange.getLowerBound() * scrollFactor);
            scrollBarModel.setValue(low);
            int ext = (int) (xAxisRange.getUpperBound() * scrollFactor - low);
            scrollBarModel.setExtent(ext);

            // restore
            scrollBarModel.addChangeListener(this);

            // check if zoomed horizontally
            //Range hdr = hvp.getHorizontalDataRange(xAxis);
            Range hdr = hvp.getDataRange(xAxis);

            double len = hdr == null ? 0 : hdr.getLength();
            chartIsZoomed |= xAxisRange.getLength() < len;
        }

        if (!chartIsZoomed && plot instanceof XYPlot) {
            // check if zoomed vertically
            XYPlot vvp = (XYPlot) plot;
            ValueAxis yAxis = vvp.getRangeAxis();
            if (yAxis != null) {
                chartIsZoomed = yAxis.getLowerBound() > yMin || yAxis.getUpperBound() < yMax;
            }
        }

        // enable "zoom-out-buttons" if chart is zoomed
        // otherwise disable them
        chartPanButton.setEnabled(chartIsZoomed);
        chartZoomOutButton.setEnabled(chartIsZoomed);
        chartFitButton.setEnabled(chartIsZoomed);
        chartScrollBar.setEnabled(chartIsZoomed);
        if (!chartIsZoomed) {
            setPanMode(false);
            chartZoomButton.setSelected(true);
        }
    } catch (Exception e) {
        MsgBox.error(e.getMessage());
    }
}

From source file:com.tradedesksoftware.ets.client.charting.ChartShiftController.java

public void mouseDragged(MouseEvent mouseEvent) {
    if (!mouseEvent.isControlDown())
        return;//from  w ww .j  a va 2 s  .c om

    if (oldx > -1 && oldy > -1) {
        ValueAxis domAxis = getPlotAxis(chartPanel.getChart(), !axesSwaped);
        ValueAxis rngAxis = getPlotAxis(chartPanel.getChart(), axesSwaped);

        int xdif = mouseEvent.getX() - oldx;
        int ydif = mouseEvent.getY() - oldy;

        final Rectangle scaledDataArea = chartPanel.getScreenDataArea();

        double xdelta = (double) xdif * domAxis.getRange().getLength() / (scaledDataArea.width);
        double ydelta = (double) ydif * rngAxis.getRange().getLength() / (scaledDataArea.height);

        domAxis.setRange(domAxis.getLowerBound() - xdelta, domAxis.getUpperBound() - xdelta);
        rngAxis.setRange(rngAxis.getLowerBound() + ydelta, rngAxis.getUpperBound() + ydelta);
    }

    oldx = mouseEvent.getX();
    oldy = mouseEvent.getY();
}

From source file:edu.dlnu.liuwenpeng.render.CandlestickRenderer.java

/**    
* Initialises the renderer then returns the number of 'passes' through the    
* data that the renderer will require (usually just one).  This method    
* will be called before the first item is rendered, giving the renderer    
* an opportunity to initialise any state information it wants to maintain.    
* The renderer can do nothing if it chooses.    
*    //from  www.  j  a  va  2  s.c om
* @param g2  the graphics device.    
* @param dataArea  the area inside the axes.    
* @param plot  the plot.    
* @param dataset  the data.    
* @param info  an optional info collection object to return data back to    
*              the caller.    
*    
* @return The number of passes the renderer requires.    
*/
public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset dataset,
        PlotRenderingInfo info) {

    // calculate the maximum allowed candle width from the axis...    
    ValueAxis axis = plot.getDomainAxis();
    double x1 = axis.getLowerBound();
    double x2 = x1 + this.maxCandleWidthInMilliseconds;
    RectangleEdge edge = plot.getDomainAxisEdge();
    double xx1 = axis.valueToJava2D(x1, dataArea, edge);
    double xx2 = axis.valueToJava2D(x2, dataArea, edge);
    this.maxCandleWidth = Math.abs(xx2 - xx1);
    // Absolute value, since the relative x    
    // positions are reversed for horizontal orientation    

    // calculate the highest volume in the dataset...    
    if (this.drawVolume) {
        OHLCDataset highLowDataset = (OHLCDataset) dataset;
        this.maxVolume = 0.0;
        for (int series = 0; series < highLowDataset.getSeriesCount(); series++) {
            for (int item = 0; item < highLowDataset.getItemCount(series); item++) {
                double volume = highLowDataset.getVolumeValue(series, item);
                if (volume > this.maxVolume) {
                    this.maxVolume = volume;
                }

            }
        }
    }

    return new XYItemRendererState(info);
}

From source file:apidemo.PanScrollZoomDemo.java

/**
 * Handles a {@link ChartChangeEvent}.//w w  w.  jav  a  2 s  .  c om
 * 
 * @param event  the event.
 */
public void chartChanged(final ChartChangeEvent event) {
    try {
        if (event.getChart() == null) {
            return;
        }

        final BoundedRangeModel scrollBarModel = this.scrollBar.getModel();
        if (scrollBarModel == null) {
            return;
        }

        boolean chartIsZoomed = false;

        final Plot plot = event.getChart().getPlot();
        if (plot instanceof XYPlot) {
            final XYPlot hvp = (XYPlot) plot;
            final ValueAxis xAxis = hvp.getDomainAxis();
            final Range xAxisRange = xAxis.getRange();

            // avoid recursion
            scrollBarModel.removeChangeListener(this);

            final int low = (int) (xAxisRange.getLowerBound() * this.scrollFactor);
            scrollBarModel.setValue(low);
            final int ext = (int) (xAxisRange.getUpperBound() * this.scrollFactor - low);
            scrollBarModel.setExtent(ext);

            // restore
            scrollBarModel.addChangeListener(this);

            // check if zoomed horizontally
            //Range hdr = hvp.getHorizontalDataRange(xAxis);
            final Range hdr = hvp.getDataRange(xAxis);

            final double len = hdr == null ? 0 : hdr.getLength();
            chartIsZoomed |= xAxisRange.getLength() < len;
        }

        if (!chartIsZoomed && plot instanceof XYPlot) {
            // check if zoomed vertically
            final XYPlot vvp = (XYPlot) plot;
            ValueAxis yAxis = vvp.getRangeAxis();
            if (yAxis != null) {
                chartIsZoomed = yAxis.getLowerBound() > this.primYMinMax[0]
                        || yAxis.getUpperBound() < this.primYMinMax[1];

                // right y-axis
                if (!chartIsZoomed && plot instanceof XYPlot) {
                    final XYPlot xyPlot = (XYPlot) plot;
                    yAxis = xyPlot.getRangeAxis(1);
                    if (yAxis != null) {
                        chartIsZoomed = yAxis.getLowerBound() > this.secondYMinMax[0]
                                || yAxis.getUpperBound() < this.secondYMinMax[1];
                    }
                }
            }
        }

        // enable "zoom-out-buttons" if chart is zoomed
        // otherwise disable them
        this.panButton.setEnabled(chartIsZoomed);
        this.zoomOutButton.setEnabled(chartIsZoomed);
        this.fitButton.setEnabled(chartIsZoomed);
        this.scrollBar.setEnabled(chartIsZoomed);
        if (!chartIsZoomed) {
            setPanMode(false);
            this.zoomButton.setSelected(true);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.esa.snap.rcp.statistics.ScatterPlotPanel.java

private void computeRegressionAndAcceptableDeviationData() {
    acceptableDeviationDataset.removeAllSeries();
    regressionDataset.removeAllSeries();
    getPlot().removeAnnotation(r2Annotation);
    if (computedDatas != null) {
        final ValueAxis domainAxis = getPlot().getDomainAxis();
        final double min = domainAxis.getLowerBound();
        final double max = domainAxis.getUpperBound();
        acceptableDeviationDataset.addSeries(computeAcceptableDeviationData(min, max));
        if (scatterPlotModel.showRegressionLine) {
            final XYIntervalSeries series = computeRegressionData(min, max);
            if (series != null) {
                regressionDataset.addSeries(series);
                computeCoefficientOfDetermination();
            }//w ww  .ja va 2  s .com
        }
    }
}

From source file:ch.algotrader.client.chart.ChartTab.java

private void initAxis() {

    DateAxis domainAxis = (DateAxis) getPlot().getDomainAxis();

    // configure the Date Axis (if startTime & endTime is set)
    if (this.chartDefinition.getStartTime() != null && this.chartDefinition.getEndTime() != null
            && !this.chartDefinition.getStartTime().equals(this.chartDefinition.getEndTime())) {

        // creat the SegmentedTimeline
        long startTime = this.chartDefinition.getStartTime().getTime();
        long endTime = this.chartDefinition.getEndTime().getTime();
        if (endTime == -3600000) {
            // adjust 00:00
            endTime += 86400000;//  w w  w.  j a  va2 s  . c o m
        }
        long segmentSize = 60 * 1000; // minute
        int segmentsIncluded = (int) (endTime - startTime) / (60 * 1000);
        int segmentsExcluded = 24 * 60 - segmentsIncluded;
        SegmentedTimeline timeline = new SegmentedTimeline(segmentSize, segmentsIncluded, segmentsExcluded);

        Date fromDate = domainAxis.getMinimumDate();
        Date toDate = domainAxis.getMaximumDate();
        long fromTime = fromDate.getTime();
        long toTime = toDate.getTime();

        // get year/month/day from fromTime and hour/minute from diagrm.startTime
        Date truncatedDate = DateUtils.truncate(fromDate, Calendar.DAY_OF_MONTH);
        Calendar truncatedCalendar = DateUtils.toCalendar(truncatedDate);
        Calendar startCalendar = DateUtils.toCalendar(this.chartDefinition.getStartTime());
        truncatedCalendar.set(Calendar.HOUR_OF_DAY, startCalendar.get(Calendar.HOUR_OF_DAY));
        truncatedCalendar.set(Calendar.MINUTE, startCalendar.get(Calendar.MINUTE));

        timeline.setStartTime(truncatedCalendar.getTimeInMillis());
        timeline.setBaseTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());
        timeline.addBaseTimelineExclusions(fromTime, toTime);
        timeline.setAdjustForDaylightSaving(true);

        domainAxis.setTimeline(timeline);
    }

    // make sure the markers are within the rangeAxis
    ValueAxis rangeAxis = getPlot().getRangeAxis();
    for (Marker marker : this.markers.values()) {

        if (marker instanceof ValueMarker) {

            ValueMarker valueMarker = (ValueMarker) marker;
            if (marker.getAlpha() > 0 && valueMarker.getValue() != 0.0) {

                if (valueMarker.getValue() < rangeAxis.getLowerBound()) {
                    rangeAxis.setLowerBound(valueMarker.getValue());
                    marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
                    marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
                }

                if (valueMarker.getValue() > rangeAxis.getUpperBound()) {
                    rangeAxis.setUpperBound(valueMarker.getValue());
                    marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
                    marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
                }
            }
        } else {

            IntervalMarker intervalMarker = (IntervalMarker) marker;
            if (marker.getAlpha() > 0 && intervalMarker.getStartValue() != 0.0) {

                if (intervalMarker.getStartValue() < rangeAxis.getLowerBound()) {
                    rangeAxis.setLowerBound(intervalMarker.getStartValue());
                    marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
                    marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
                }

                if (intervalMarker.getEndValue() > rangeAxis.getUpperBound()) {
                    rangeAxis.setUpperBound(intervalMarker.getEndValue());
                    marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
                    marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
                }
            }
        }
    }
}

From source file:org.esa.beam.visat.toolviews.stat.ScatterPlotPanel.java

private void computeRegressionAndAcceptableDeviationData() {
    acceptableDeviationDataset.removeAllSeries();
    regressionDataset.removeAllSeries();
    getPlot().removeAnnotation(r2Annotation);
    if (computedDatas != null) {
        final ValueAxis domainAxis = getPlot().getDomainAxis();
        final double min = domainAxis.getLowerBound();
        final double max = domainAxis.getUpperBound();
        acceptableDeviationDataset.addSeries(computeAcceptableDeviationData(min, max));
        if (scatterPlotModel.showRegressionLine) {
            regressionDataset.addSeries(computeRegressionData(min, max));
            computeCoefficientOfDetermination();
        }//from ww  w.  ja v a2s .c om
    }
}