List of usage examples for org.jfree.chart.axis ValueAxis getRange
public Range getRange()
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * calculates the correct height with multiple iterations Domain and Range axes need to share the * same unit (e.g. mm)/*from w w w . j ava 2s. c om*/ * * @param myChart * @param copyToNewPanel * @param dataWidth width of data * @param axis for width calculation * @return */ public static double calcHeightToWidth(ChartPanel myChart, double chartWidth, double estimatedHeight, int iterations, boolean copyToNewPanel) { // if(myChart.getChartRenderingInfo()==null || // myChart.getChartRenderingInfo().getChartArea()==null || // myChart.getChartRenderingInfo().getChartArea().getWidth()==0) // result double height = estimatedHeight; double lastH = height; makeChartResizable(myChart); // paint on a ghost panel JPanel parent = (JPanel) myChart.getParent(); JPanel p = copyToNewPanel ? new JPanel() : parent; if (copyToNewPanel) p.add(myChart, BorderLayout.CENTER); try { for (int i = 0; i < iterations; i++) { // paint on ghost panel with estimated height (if copy panel==true) myChart.setSize((int) chartWidth, (int) estimatedHeight); myChart.paintImmediately(myChart.getBounds()); XYPlot plot = (XYPlot) myChart.getChart().getPlot(); ChartRenderingInfo info = myChart.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); Rectangle2D chartArea = info.getChartArea(); // calc title space: will be added later to the right plot size double titleWidth = chartArea.getWidth() - dataArea.getWidth(); double titleHeight = chartArea.getHeight() - dataArea.getHeight(); // calc right plot size with axis dim. // real plot width is given by factor; double realPW = chartWidth - titleWidth; // ranges ValueAxis domainAxis = plot.getDomainAxis(); org.jfree.data.Range x = domainAxis.getRange(); ValueAxis rangeAxis = plot.getRangeAxis(); org.jfree.data.Range y = rangeAxis.getRange(); // real plot height can be calculated by double realPH = realPW / x.getLength() * y.getLength(); // the real height height = realPH + titleHeight; // for next iteration estimatedHeight = height; if ((int) lastH == (int) height) break; else lastH = height; } } catch (Exception ex) { ex.printStackTrace(); } if (copyToNewPanel) { // reset to frame p.removeAll(); parent.add(myChart); } return height; }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIHelper.java
/*********************************************************************************************** * Calculate and update the Domain Offset Crosshair and draw the crosshair on the XYPlot. * Return the value set on the XYPlot, or Double.MIN_VALUE on failure. * * @param chartui//from w ww .j ava 2s . c om * @param valueminimum * @param valuemaximum * @param offset * @param debug * * @return double */ public static double updateDomainCrosshairForOffsetControl(final ChartUIComponentPlugin chartui, final int valueminimum, final int valuemaximum, final double offset, final boolean debug) { final String SOURCE = "ChartHelper.updateDomainCrosshairForOffsetControl() "; double dblDomainCrosshairXYPlot; dblDomainCrosshairXYPlot = Double.MIN_VALUE; if (chartui != null) { if ((chartui.getChartPanel() != null) && (chartui.getChartPanel().getChart() != null) && (chartui.getChartPanel().getChart().getPlot() != null)) { final XYPlot plot; final ValueAxis domainAxis; final Range range; final double dblPositionFraction; // Save the supplied new value chartui.setDomainCrosshair(offset); plot = (XYPlot) chartui.getChartPanel().getChart().getPlot(); domainAxis = plot.getDomainAxis(); range = domainAxis.getRange(); if (offset >= 0) { //dblPositionFraction = (offset - (double)valueminimum) / (double)(valuemaximum - valueminimum); dblPositionFraction = (offset * 2.0) / (double) (valuemaximum - valueminimum); } else { dblPositionFraction = 0.0; } dblDomainCrosshairXYPlot = domainAxis.getLowerBound() + (dblPositionFraction * range.getLength()); // Update the XYPlot plot.setDomainCrosshairValue(dblDomainCrosshairXYPlot); FrameworkSingletons.LOGGER.debug(debug, SOURCE + "Domain Crosshair updated [value.knob=" + offset + "] [value.xyplot=" + dblDomainCrosshairXYPlot + "] [domain.lowerbound=" + domainAxis.getLowerBound() + "] [domain.upperbound=" + domainAxis.getUpperBound() + "] [value.fraction=" + dblPositionFraction + "] [value.minimum=" + valueminimum + "] [value.maximum=" + valuemaximum + "]"); } else { FrameworkSingletons.LOGGER.debug(debug, SOURCE + "There is no Chart, so cannot update Domain Crosshair on XYPlot"); // Save a default value chartui.setDomainCrosshair(valueminimum); dblDomainCrosshairXYPlot = Double.MIN_VALUE; } } return (dblDomainCrosshairXYPlot); }
From source file:net.sf.mzmine.chartbasics.listener.AxisRangeChangedListener.java
@Override public void axisChanged(AxisChangeEvent e) { ValueAxis a = (ValueAxis) e.getAxis(); Range r = a.getRange(); if (r != null && (lastRange == null || !r.equals(lastRange))) { // range has changed axisRangeChanged(chart, a, lastRange, r); }// w w w .jav a 2s. c o m lastRange = r; }
From source file:net.sf.mzmine.chartbasics.listener.AxesRangeChangedListener.java
@Override public void axisChanged(AxisChangeEvent e) { ValueAxis a = (ValueAxis) e.getAxis(); Range r = a.getRange(); boolean found = false; int i = 0;/* w ww . j av a 2s .c o m*/ for (i = 0; i < axis.length && !found; i++) { // get index of axis if (axis[i] == null) break; if (a.equals(axis[i])) { found = true; break; } } if (i >= axis.length) i = axis.length - 1; // insert if not found if (!found) { axis[i] = a; } if (r != null && (lastRange[i] == null || !r.equals(lastRange[i]))) { // range has changed axesRangeChanged(chart, a, lastRange[i], r); } lastRange[i] = r; }
From source file:playground.thibautd.utils.charts.ChartsAxisUnifier.java
public void addChart(final JFreeChart chart) { charts.add(chart);/*from w w w . jav a 2 s . c om*/ if (unifyX) { Plot plot = chart.getPlot(); if (plot instanceof XYPlot) { ValueAxis axis = chart.getXYPlot().getDomainAxis(); Range range = axis.getRange(); lowerX = Math.min(lowerX, range.getLowerBound()); upperX = Math.max(upperX, range.getUpperBound()); } } if (unifyY) { Plot plot = chart.getPlot(); ValueAxis axis; if (plot instanceof XYPlot) { axis = chart.getXYPlot().getRangeAxis(); } else if (plot instanceof CategoryPlot) { axis = chart.getCategoryPlot().getRangeAxis(); } else { return; } Range range = axis.getRange(); lowerY = Math.min(lowerY, range.getLowerBound()); upperY = Math.max(upperY, range.getUpperBound()); } }
From source file:com.bdb.weather.display.day.DayTemperaturePane.java
@Override public void finishLoadData() { if (recordHigh == null || recordLow == null) return;/*from ww w.j av a2 s . com*/ ValueAxis axis = getPlot().getRangeAxis(); Range range = axis.getRange(); double lowRange = recordLow.get() < range.getLowerBound() ? recordLow.get() : range.getLowerBound(); double highRange = recordHigh.get() > range.getUpperBound() ? recordHigh.get() : range.getUpperBound(); axis.setAutoRange(false); axis.setRange(lowRange - 10.0, highRange + 10.0); }
From source file:org.jfree.eastwood.GCategoryPlot.java
/** * Draws the gridlines for the plot.// w w w. j a v a2 s . co m * * @param g2 the graphics device. * @param dataArea the area inside the axes. * @param ticks the ticks. * * @see #drawDomainGridlines(Graphics2D, Rectangle2D) */ protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) { // draw the range grid lines, if any... if (isRangeGridlinesVisible()) { Stroke gridStroke = getRangeGridlineStroke(); Paint gridPaint = getRangeGridlinePaint(); if ((gridStroke != null) && (gridPaint != null)) { ValueAxis axis = getRangeAxis(); if (axis != null) { double lower = axis.getRange().getLowerBound(); double upper = axis.getRange().getUpperBound(); double y = lower; while (y <= upper) { Paint paint = gridPaint; if ((y == lower || y == upper) && gridPaint instanceof Color) { Color c = (Color) gridPaint; paint = new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha() / 3); } try { setRangeGridlinePaint(paint); getRenderer().drawRangeGridline(g2, this, getRangeAxis(), dataArea, y); } finally { setRangeGridlinePaint(gridPaint); } y += this.yAxisStepSize; } } } } }
From source file:org.jfree.chart.demo.bottom_slider.java
/** * Create the panel./*from ww w .java 2 s . c o m*/ */ public bottom_slider(Color color, ArrayList<JFreeChart> chart, final Graphic graph, int num) { setBounds(5, 380, 740, 100); setLayout(null); charts = chart; plot = charts.get(num).getXYPlot(); table = new JTable( new Object[][] { { "Slider", "X", "Y", "X1-X2", "Y1-Y2" }, { "Slider1", null, null, null, null }, { "Slider2", null, null, null, null } }, new String[] { "Slider", "X", "Y", "X1-X2", "Y1-Y2" }); setBackground(color); table.setBounds(255, 22, 485, 48); add(table); slider_2 = new JSlider(); slider_2.setBounds(5, 22, 250, 20); slider_2.setBackground(color); slider_2.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { try { int value = slider_2.getValue(); ValueAxis domainAxis = plot.getDomainAxis(); Range range = domainAxis.getRange(); X1 = domainAxis.getLowerBound() + (value / 100.0) * range.getLength(); int i = 0; for (; i < graph.mas_x.size(); i++) { // System.out.println("X"+ Arrays.toString(graph.mas_x.toArray())); if (graph.mas_x.get(i).doubleValue() <= X1) { } else { break; } } Y1 = graph.mas_y.get(i).doubleValue(); } catch (Exception e1) { if (e.toString() == "java.lang.IndexOutOfBoundsException") Y1 = graph.mas_y.get(graph.mas_y.size() - 1).doubleValue(); } plot.removeDomainMarker(distanceTiers2); distanceTiers2 = new ValueMarker(X1); distanceTiers2.setPaint(Color.BLACK); plot.addDomainMarker(distanceTiers2); table.setValueAt("" + new BigDecimal(X1).setScale(3, RoundingMode.UP).doubleValue(), 1, 1); table.setValueAt("" + new BigDecimal(Y1).setScale(3, RoundingMode.UP).doubleValue(), 1, 2); table.setValueAt("" + new BigDecimal(X2).setScale(3, RoundingMode.UP).doubleValue(), 2, 1); table.setValueAt("" + new BigDecimal(Y2).setScale(3, RoundingMode.UP).doubleValue(), 2, 2); table.setValueAt("" + new BigDecimal(Math.abs(X2 - X1)).setScale(3, RoundingMode.UP).doubleValue(), 2, 3); table.setValueAt("" + new BigDecimal(Math.abs(X2 - X1)).setScale(3, RoundingMode.UP).doubleValue(), 1, 3); table.setValueAt("" + new BigDecimal(Math.abs(Y2 - Y1)).setScale(3, RoundingMode.UP).doubleValue(), 2, 4); table.setValueAt("" + new BigDecimal(Math.abs(Y2 - Y1)).setScale(3, RoundingMode.UP).doubleValue(), 1, 4); } }); add(slider_2); slider_3 = new JSlider(); slider_3.setBounds(5, 55, 250, 20); slider_3.setBackground(color); slider_3.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { try { int value = slider_3.getValue(); ValueAxis domainAxis = plot.getDomainAxis(); Range range = domainAxis.getRange(); X2 = domainAxis.getLowerBound() + (value / 100.0) * range.getLength(); plot.removeDomainMarker(distanceTiers1); distanceTiers1 = new ValueMarker(X2); distanceTiers1.setPaint(Color.BLACK); plot.addDomainMarker(distanceTiers1); int i = 0; for (; i < graph.mas_x.size(); i++) { if (graph.mas_x.get(i).doubleValue() <= X2) { } else { break; } } Y2 = graph.mas_y.get(i).doubleValue(); } catch (Exception e1) { if (e.toString() == "java.lang.IndexOutOfBoundsException") Y1 = graph.mas_y.get(graph.mas_y.size() - 1).doubleValue(); } table.setValueAt("" + new BigDecimal(X1).setScale(3, RoundingMode.UP).doubleValue(), 1, 1); table.setValueAt("" + new BigDecimal(Y1).setScale(3, RoundingMode.UP).doubleValue(), 1, 2); table.setValueAt("" + new BigDecimal(X2).setScale(3, RoundingMode.UP).doubleValue(), 2, 1); table.setValueAt("" + new BigDecimal(Y2).setScale(3, RoundingMode.UP).doubleValue(), 2, 2); table.setValueAt("" + new BigDecimal(Math.abs(X2 - X1)).setScale(3, RoundingMode.UP).doubleValue(), 2, 3); table.setValueAt("" + new BigDecimal(Math.abs(X2 - X1)).setScale(3, RoundingMode.UP).doubleValue(), 1, 3); table.setValueAt("" + new BigDecimal(Math.abs(Y2 - Y1)).setScale(3, RoundingMode.UP).doubleValue(), 2, 4); table.setValueAt("" + new BigDecimal(Math.abs(Y2 - Y1)).setScale(3, RoundingMode.UP).doubleValue(), 1, 4); } }); add(slider_3); }
From source file:net.sf.jasperreports.customizers.axis.AbstractAxisCustomizer.java
protected void configValueAxis(ValueAxis valueAxis, String minProp, String maxProp) { if (valueAxis != null) { Double rangeMin = getDoubleProperty(minProp); Double rangeMax = getDoubleProperty(maxProp); if (rangeMin != null || rangeMax != null) { valueAxis.setRange(rangeMin == null ? valueAxis.getRange().getLowerBound() : rangeMin, rangeMax == null ? valueAxis.getRange().getUpperBound() : rangeMax); }//www . j a va 2 s . c o m } }
From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.AdvancedXY_PlotPanel.java
@Override public void stateChanged(ChangeEvent e) { int value = this.slider.getValue(); XYPlot plot = (XYPlot) this.getChart().getPlot(); ValueAxis domainAxis = plot.getDomainAxis(); Range range = domainAxis.getRange(); double c = domainAxis.getLowerBound() + (value / 100.0) * range.getLength(); // displays the vertical crosshair in the desired position plot.setDomainCrosshairValue(c);/*from w ww .ja v a 2 s . com*/ // the cross hair is keyed to the horizontal slider - for the time domain axis setCrossHairDomainIndex(); }