List of usage examples for org.jfree.data Range getLowerBound
public double getLowerBound()
From source file:ucar.unidata.idv.control.chart.ChartHolder.java
/** * Move plot up/down.//from w ww.ja v a 2 s .c om * * @param up up */ private void upDownPlot(boolean up) { if (!(plot instanceof XYPlot)) { return; } XYPlot xyPlot = (XYPlot) plot; int cnt = xyPlot.getRangeAxisCount(); for (int i = 0; i < cnt; i++) { ValueAxis axis = (ValueAxis) xyPlot.getRangeAxis(i); org.jfree.data.Range range = axis.getRange(); double width = range.getUpperBound() - range.getLowerBound(); double width2 = width / 2.0; double step = (up ? width * 0.1 : -width * 0.1); axis.centerRange(range.getLowerBound() + step + width2); } }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
public void chartChanged(ChartChangeEvent event) { try {/*from w w w . jav a 2 s . c om*/ 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:org.trade.ui.chart.CandlestickChart.java
/** * A demonstration application showing a candlestick chart. * //from w w w . j av a 2s . c o m * @param title * the frame title. * @param strategyData * StrategyData */ public CandlestickChart(final String title, StrategyData strategyData, Tradingday tradingday) { this.strategyData = strategyData; this.setLayout(new BorderLayout()); // Used to mark the current price stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 10, 3 }, 0); valueMarker = new ValueMarker(0.00, Color.black, stroke); this.chart = createChart(this.strategyData, title, tradingday); BlockContainer container = new BlockContainer(new BorderArrangement()); container.add(titleLegend1, RectangleEdge.LEFT); container.add(titleLegend2, RectangleEdge.RIGHT); container.add(new EmptyBlock(2000, 0)); CompositeTitle legends = new CompositeTitle(container); legends.setPosition(RectangleEdge.BOTTOM); this.chart.addSubtitle(legends); final ChartPanel chartPanel = new ChartPanel(this.chart); chartPanel.setFillZoomRectangle(true); chartPanel.setMouseZoomable(true, true); chartPanel.setRefreshBuffer(true); chartPanel.setDoubleBuffered(true); chartPanel.setVerticalAxisTrace(true); chartPanel.setHorizontalAxisTrace(true); chartPanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseMoved(ChartMouseEvent e) { } public void chartMouseClicked(final ChartMouseEvent e) { CombinedDomainXYPlot combinedXYplot = (CombinedDomainXYPlot) e.getChart().getPlot(); @SuppressWarnings("unchecked") List<XYPlot> subplots = combinedXYplot.getSubplots(); if (e.getTrigger().getClickCount() == 2) { double xItem = 0; double yItem = 0; if (e.getEntity() instanceof XYItemEntity) { XYItemEntity xYItemEntity = ((XYItemEntity) e.getEntity()); xItem = xYItemEntity.getDataset().getXValue(xYItemEntity.getSeriesIndex(), xYItemEntity.getItem()); yItem = xYItemEntity.getDataset().getYValue(xYItemEntity.getSeriesIndex(), xYItemEntity.getItem()); } else { PlotEntity plotEntity = ((PlotEntity) e.getEntity()); XYPlot plot = (XYPlot) plotEntity.getPlot(); xItem = plot.getDomainCrosshairValue(); yItem = plot.getRangeCrosshairValue(); } for (XYPlot xyplot : subplots) { double x = xyplot.getDomainCrosshairValue(); double y = xyplot.getRangeCrosshairValue(); /* * If the cross hair is from a right-hand y axis we need * to convert this to a left-hand y axis. */ String rightAxisName = ", Price: "; double rangeLowerLeft = 0; double rangeUpperLeft = 0; double rangeLowerRight = 0; double rangeUpperRight = 0; double yRightLocation = 0; for (int index = 0; index < xyplot.getRangeAxisCount(); index++) { AxisLocation axisLocation = xyplot.getRangeAxisLocation(index); Range range = xyplot.getRangeAxis(index).getRange(); if (axisLocation.equals(AxisLocation.BOTTOM_OR_LEFT) || axisLocation.equals(AxisLocation.TOP_OR_LEFT)) { rangeLowerLeft = range.getLowerBound(); rangeUpperLeft = range.getUpperBound(); rightAxisName = ", " + xyplot.getRangeAxis(index).getLabel() + ": "; } if (y >= range.getLowerBound() && y <= range.getUpperBound() && (axisLocation.equals(AxisLocation.BOTTOM_OR_RIGHT) || axisLocation.equals(AxisLocation.TOP_OR_RIGHT))) { rangeUpperRight = range.getUpperBound(); rangeLowerRight = range.getLowerBound(); } } if ((rangeUpperRight - rangeLowerRight) > 0) { yRightLocation = rangeLowerLeft + ((rangeUpperLeft - rangeLowerLeft) * ((y - rangeLowerRight) / (rangeUpperRight - rangeLowerRight))); } else { yRightLocation = y; } String text = " Time: " + dateFormatShort.format(new Date((long) (x))) + rightAxisName + new Money(y); if (x == xItem && y == yItem) { titleLegend1.setText(text); if (null == clickCrossHairs) { clickCrossHairs = new XYTextAnnotation(text, x, yRightLocation); clickCrossHairs.setTextAnchor(TextAnchor.BOTTOM_LEFT); xyplot.addAnnotation(clickCrossHairs); } else { clickCrossHairs.setText(text); clickCrossHairs.setX(x); clickCrossHairs.setY(yRightLocation); } } } } else if (e.getTrigger().getClickCount() == 1 && null != clickCrossHairs) { for (XYPlot xyplot : subplots) { if (xyplot.removeAnnotation(clickCrossHairs)) { clickCrossHairs = null; titleLegend1.setText(" Time: 0, Price :0.0"); break; } } } } }); this.add(chartPanel, null); this.strategyData.getCandleDataset().getSeries(0).addChangeListener(this); }
From source file:ucar.unidata.idv.control.chart.PlotWrapper.java
/** * Pan the plot/*from w w w. j a v a 2 s. c o m*/ * * @param right to right * @param percent by how much */ protected void panPlot(boolean right, double percent) { if (!(chart.getPlot() instanceof XYPlot)) { return; } XYPlot plot = (XYPlot) chart.getPlot(); int cnt = plot.getDomainAxisCount(); for (int i = 0; i < cnt; i++) { ValueAxis axis = (ValueAxis) plot.getDomainAxis(i); org.jfree.data.Range range = axis.getRange(); double width = range.getUpperBound() - range.getLowerBound(); double width2 = width / 2.0; double step = (right ? width * percent : -width * percent); axis.centerRange(range.getLowerBound() + step + width2); } }
From source file:ucar.unidata.idv.control.chart.PlotWrapper.java
/** * Move plot up/down./*from ww w . jav a2 s . c om*/ * * @param up up */ private void upDownPlot(boolean up) { if (!(chart.getPlot() instanceof XYPlot)) { return; } XYPlot plot = (XYPlot) chart.getPlot(); int cnt = plot.getRangeAxisCount(); for (int i = 0; i < cnt; i++) { ValueAxis axis = (ValueAxis) plot.getRangeAxis(i); org.jfree.data.Range range = axis.getRange(); double width = range.getUpperBound() - range.getLowerBound(); double width2 = width / 2.0; double step = (up ? width * 0.1 : -width * 0.1); axis.centerRange(range.getLowerBound() + step + width2); } }
From source file:org.fhcrc.cpl.viewer.gui.SpectrumComponent.java
protected void copyChartData() { if (null == _chart || null == _spectrum) return;//from w w w . ja v a 2s .co m XYPlot xyplot; if (_chart.getPlot() instanceof XYPlot) { xyplot = _chart.getXYPlot(); } else { // UNDONE: return; } ValueAxis domainAxis = xyplot.getDomainAxis(); Range range = domainAxis.getRange(); double min = range.getLowerBound(); double max = range.getUpperBound(); float[] x = _spectrum[0]; float[] y = _spectrum[1]; int start = Arrays.binarySearch(x, (float) min); if (start < 0) start = -(start + 1); int end = Arrays.binarySearch(x, (float) max); if (end < 0) end = -(end + 1); StringBuffer sb = new StringBuffer(20 * (end - start)); for (int i = start; i < end; i++) sb.append(x[i]).append('\t').append(y[i]).append('\n'); StringSelection sel = new StringSelection(sb.toString()); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, sel); }
From source file:com.rapidminer.gui.plotter.charts.HistogramChart.java
private void setRange(ValueAxis axis) { Range range = null; for (int c = 0; c < this.dataTable.getNumberOfColumns(); c++) { if (this.columns[c]) { if (range == null) { range = getRangeForDimension(c); } else { Range newRange = getRangeForDimension(c); if (newRange != null) { range = new Range(MathFunctions.robustMin(range.getLowerBound(), newRange.getLowerBound()), MathFunctions.robustMax(range.getUpperBound(), newRange.getUpperBound())); }//from w ww. j a v a 2s . co m } } } if (range != null) { axis.setRange(range); } else { axis.setAutoRange(true); } }
From source file:org.pentaho.platform.uifoundation.chart.DialWidgetDefinition.java
/** * Add an interval (MeterInterval) to the dial definition. The interval defines a range and how it should be * painted.// ww w.j av a2 s .c om * <p/> * The dial images here have three intervals. The lowest interval has a minimum of 0 and a maximum of 30. * <p/> * Intervals have a color. In this image the lowest interval color is set to red. <br/> * <img src="doc-files/DialWidgetDefinition-5.png"> * <p/> * Intervals have a text color. In this image the lowest interval text color is set to red. This affects the * outer rim, the interval value text <br/> * <img src="doc-files/DialWidgetDefinition-6.png"> * * @param interval * A MeterInterval that defines an interval (range) on the dial */ public void addInterval(final MeterInterval interval) { intervals.add(interval); Range range = interval.getRange(); double min = range.getLowerBound(); double max = range.getUpperBound(); if (rangeLimited && (intervals.size() == 1)) { setMinimum(min); setMaximum(max); } else { if (min < getMinimum()) { setMinimum(min); } if (max > getMaximum()) { setMaximum(max); } } }
From source file:org.tsho.dmc2.core.chart.LyapunovRenderer.java
public void initializeVsTime(VariableDoubles parameters, VariableDoubles initialValues, Range timeRange) { this.parameters.putAll(parameters); this.initialPoint.putAll(initialValues); this.lower = (int) timeRange.getLowerBound(); this.upper = (int) timeRange.getUpperBound(); this.type = TYPE_VSTIME; }
From source file:fr.amap.lidar.amapvox.chart.VoxelsToChart.java
public JFreeChart[] getVegetationProfileCharts(LayerReference reference, float maxPAD) { boolean inverseRangeAxis; inverseRangeAxis = !(reference == LayerReference.FROM_ABOVE_GROUND); int quadratNumber = getQuadratNumber(split, length); JFreeChart[] charts = new JFreeChart[quadratNumber]; for (int i = 0; i < quadratNumber; i++) { XYSeriesCollection dataset = new XYSeriesCollection(); for (VoxelFileChart voxelFile : voxelFiles) { int[] indices = getIndiceRange(voxelFile, i); XYSeries serie = createVegetationProfileSerie(voxelFile.reader, voxelFile.label, indices[0], indices[1], reference, maxPAD); dataset.addSeries(serie);/*ww w . j ava 2 s . com*/ } List<XYSeries> series = dataset.getSeries(); double correlationValue = Double.NaN; if (series.size() == 2) { XYSeries firstSerie = series.get(0); XYSeries secondSerie = series.get(1); Map<Double, Double[]> valuesMap = new HashMap<>(); for (int j = 0; j < firstSerie.getItemCount(); j++) { Double[] value = new Double[] { firstSerie.getDataItem(j).getXValue(), Double.NaN }; valuesMap.put(firstSerie.getDataItem(j).getYValue(), value); } for (int j = 0; j < secondSerie.getItemCount(); j++) { Double[] value = valuesMap.get(Double.valueOf(secondSerie.getDataItem(j).getYValue())); if (value == null) { valuesMap.put(secondSerie.getDataItem(j).getYValue(), new Double[] { Double.NaN, secondSerie.getDataItem(j).getXValue() }); } else if (Double.isNaN(value[1])) { value[1] = secondSerie.getDataItem(j).getXValue(); valuesMap.put(secondSerie.getDataItem(j).getYValue(), value); } } List<Double> firstList = new ArrayList<>(); List<Double> secondList = new ArrayList<>(); Iterator<Map.Entry<Double, Double[]>> iterator = valuesMap.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<Double, Double[]> next = iterator.next(); Double[] value = next.getValue(); if (!Double.isNaN(value[0]) && !Double.isNaN(value[1])) { firstList.add(value[0]); secondList.add(value[1]); } } double[] firstArray = new double[firstList.size()]; double[] secondArray = new double[secondList.size()]; for (int j = 0; j < firstList.size(); j++) { firstArray[j] = firstList.get(j); secondArray[j] = secondList.get(j); } PearsonsCorrelation correlation = new PearsonsCorrelation(); correlationValue = correlation.correlation(firstArray, secondArray); } charts[i] = createChart("Vegetation profile" + " - quadrat " + (i + 1), dataset, "PAD", reference.getLabel()); if (!Double.isNaN(correlationValue)) { charts[i].addSubtitle( new TextTitle("R2 = " + (Math.round(Math.pow(correlationValue, 2) * 100)) / 100.0)); } ((XYPlot) charts[i].getPlot()).getRangeAxis().setInverted(inverseRangeAxis); } //set quadrats ranges double minX = 0; double maxX = 0; double minY = 0; double maxY = 0; int id = 0; for (JFreeChart chart : charts) { XYPlot plot = (XYPlot) chart.getPlot(); Range rangeOfRangeAxis = plot.getDataRange(plot.getRangeAxis()); Range rangeOfDomainAxis = plot.getDataRange(plot.getDomainAxis()); double currentMinY = rangeOfRangeAxis.getLowerBound(); double currentMaxY = rangeOfRangeAxis.getUpperBound(); double currentMinX = rangeOfDomainAxis.getLowerBound(); double currentMaxX = rangeOfDomainAxis.getUpperBound(); if (id == 0) { minX = currentMinX; maxX = currentMaxX; minY = currentMinY; maxY = currentMaxY; } else { if (currentMinX < minX) { minX = currentMinX; } if (currentMaxX > maxX) { maxX = currentMaxX; } if (currentMinY < minY) { minY = currentMinY; } if (currentMaxY > maxY) { maxY = currentMaxY; } } id++; } for (JFreeChart chart : charts) { XYPlot plot = (XYPlot) chart.getPlot(); plot.getDomainAxis().setRange(minX, maxX); plot.getRangeAxis().setRange(minY, maxY); } return charts; }