List of usage examples for org.jfree.chart.plot XYPlot getRangeAxis
public ValueAxis getRangeAxis()
From source file:org.jfree.chart.demo.BubblyBubblesDemo.java
/** * A demonstration application showing a bubble chart using matrix series. * * @param title the frame title./*from w w w . j ava 2s.c o m*/ */ public BubblyBubblesDemo(final String title) { super(title); this.series = createInitialSeries(); final MatrixSeriesCollection dataset = new MatrixSeriesCollection(this.series); final JFreeChart chart = ChartFactory.createBubbleChart(TITLE, "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); final XYPlot plot = chart.getXYPlot(); plot.setForegroundAlpha(0.5f); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setLowerBound(-0.5); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); // rangeAxis.setInverted(true); // uncoment to reproduce a bug in jFreeChart rangeAxis.setLowerBound(-0.5); final ChartPanel chartPanel = new ChartPanel(chart); // chartPanel.setVerticalZoom(true); // chartPanel.setHorizontalZoom(true); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.BubblyBubblesDemo2.java
/** * A demonstration application showing a bubble chart using matrix series. * * @param title the frame title./*w w w . j ava 2 s. c om*/ */ public BubblyBubblesDemo2(final String title) { super(title); this.series = createInitialSeries(); final MatrixSeriesCollection dataset = new MatrixSeriesCollection(this.series); final JFreeChart chart = ChartFactory.createBubbleChart(TITLE, "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.yellow)); final XYPlot plot = chart.getXYPlot(); plot.setForegroundAlpha(0.5f); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setLowerBound(-0.5); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLowerBound(-0.5); final ChartPanel chartPanel = new ChartPanel(chart); // chartPanel.setVerticalZoom(true); // chartPanel.setHorizontalZoom(true); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.LineChartDemo3.java
/** * Creates a chart.//w w w . j ava 2 s .c o m * * @param dataset a dataset. * * @return A chart based on the supplied dataset. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart Demo 3", // chart title "X", // x axis label "Y", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // get a reference to the plot for further customisation... final XYPlot plot = chart.getXYPlot(); final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); renderer.setPlotShapes(true); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
From source file:com.intel.stl.ui.main.view.DataRateChartRangeUpdater.java
@Override public void updateChartRange(JFreeChart chart, long lower, long upper) { if (lower > upper) { return;/* w ww. j a v a2s.c o m*/ } XYPlot xyplot = (XYPlot) chart.getPlot(); NumberAxis range = (NumberAxis) xyplot.getRangeAxis(); range.setRangeWithMargins(lower, upper); range.setLowerBound(0); // If upper is less than 1000, don't do anything to convert the y-axis // label and // convert the unit tick. TickUnitSource unitSrc = createTickUnits(upper); if (unitSrc != null) { // Change tick values only if upper is above 1000. range.setStandardTickUnits(unitSrc); xyplot.getRenderer().setBaseToolTipGenerator( new StandardXYToolTipGenerator("<html><b>{0}</b><br> Time: {1}<br> Data: {2}</html>", Util.getHHMMSS(), new DecimalFormat("#,##0.00" + " " + unitDes)) { private static final long serialVersionUID = 4825888117284967486L; @Override protected Object[] createItemArray(XYDataset dataset, int series, int item) { String nullXString = "null"; String nullYString = "null"; Object[] result = new Object[3]; result[0] = dataset.getSeriesKey(series).toString(); double x = dataset.getXValue(series, item); if (Double.isNaN(x) && dataset.getX(series, item) == null) { result[1] = nullXString; } else { DateFormat xDateFormat = this.getXDateFormat(); if (xDateFormat != null) { result[1] = xDateFormat.format(new Date((long) x)); } else { result[1] = this.getXFormat().format(x); } } double y = dataset.getYValue(series, item); if (Double.isNaN(y) && dataset.getY(series, item) == null) { result[2] = nullYString; } else { DateFormat yDateFormat = this.getYDateFormat(); if (yDateFormat != null) { result[2] = yDateFormat.format(new Date((long) y)); } else { result[2] = this.getYFormat().format(y / tickUnitSize); } } return result; } }); } else { range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } // y-axis label setChartRangeLabel(range); }
From source file:org.jfree.expdemo.SelectionDemo3.java
private static JFreeChart createChart(XYDataset dataset, DatasetSelectionExtension ext) { JFreeChart chart = ChartFactory.createScatterPlot("SelectionDemo3", "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainPannable(true);//from w w w .j a va2 s . c o m plot.setRangePannable(true); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); plot.setDomainGridlineStroke(new BasicStroke(0.0f)); plot.setRangeGridlineStroke(new BasicStroke(0.0f)); plot.setDomainMinorGridlinesVisible(true); plot.setRangeMinorGridlinesVisible(true); //XYItemRenderer r = plot.getRenderer(); XYDotRenderer r = new XYDotRenderer(); r.setDotHeight(2); r.setDotWidth(2); r.setSeriesPaint(0, Color.blue); r.setSeriesPaint(1, Color.green); r.setSeriesPaint(2, Color.yellow); r.setSeriesPaint(3, Color.orange); plot.setRenderer(r); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setTickMarkInsideLength(2.0f); domainAxis.setTickMarkOutsideLength(2.0f); domainAxis.setMinorTickCount(2); domainAxis.setMinorTickMarksVisible(true); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setTickMarkInsideLength(2.0f); rangeAxis.setTickMarkOutsideLength(2.0f); rangeAxis.setMinorTickCount(2); rangeAxis.setMinorTickMarksVisible(true); //add selection specific rendering IRSUtilities.setSelectedItemPaint(r, ext, Color.red); //register plot as selection change listener ext.addSelectionChangeListener(plot); return chart; }
From source file:edu.ucsd.hep.slhaviewer.view.MassGraphPanel.java
public MassGraphPanel() { this.setLayout(new BorderLayout()); dataset = new XYSeriesCollection(); JFreeChart chart = ChartFactory.createXYLineChart("Mass Spectrum", "", "mass [GeV]", dataset, PlotOrientation.VERTICAL, false, // no legend true, // add tooltips false // add urls );/* w w w . j a v a2 s . co m*/ // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) chart.getPlot(); renderer = (XYLineAndShapeRenderer) plot.getRenderer(); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setTickMarksVisible(false); domainAxis.setTickLabelsVisible(false); chart.setBackgroundPaint(Color.WHITE); // 'outside' plot.setBackgroundPaint(Color.WHITE); // 'inside' plot.setRangeGridlinePaint(Color.DARK_GRAY); this.add(new ChartPanel(chart), BorderLayout.CENTER); }
From source file:com.vgi.mafscaling.MafChartPanel.java
public void mousePressed(MouseEvent e) { Insets insets = chartPanel.getInsets(); int x = (int) ((e.getX() - insets.left) / chartPanel.getScaleX()); int y = (int) ((e.getY() - insets.top) / chartPanel.getScaleY()); ChartEntity entity = chartPanel.getChartRenderingInfo().getEntityCollection().getEntity(x, y); if (entity == null || !(entity instanceof XYItemEntity)) return;/*from ww w . ja v a2 s . co m*/ IsMovable = true; chartPanel.setCursor(new Cursor(Cursor.HAND_CURSOR)); xyItemEntity = (XYItemEntity) entity; XYPlot plot = chartPanel.getChart().getXYPlot(); Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); Point2D p = chartPanel.translateScreenToJava2D(e.getPoint()); initialMovePointY = plot.getRangeAxis().java2DToValue(p.getY(), dataArea, plot.getRangeAxisEdge()); }
From source file:org.talend.dataprofiler.chart.util.ToolTipChartComposite.java
/** * This method attempts to get a tooltip by converting the screen X,Y into Chart Area X,Y and then looking for a * data point in a data set that lies inside a hotspot around that value. * // w w w .j a v a2 s .c o m * @param point The Java 2D point * @return A string for the data at the point or null if no data is found. */ protected String getTooltipAtPoint(Point point) { String result = null; Point2D translatedPoint = this.translateScreenToJava2D(point); Plot plot = this.getChart().getPlot(); PlotRenderingInfo info = this.getChartRenderingInfo().getPlotInfo(); if (plot instanceof CombinedDomainXYPlot) { int index = info.getSubplotIndex(translatedPoint); if (index < 0) { index = 0; } plot = (Plot) ((CombinedDomainXYPlot) plot).getSubplots().get(index); info = this.getChartRenderingInfo().getPlotInfo().getSubplotInfo(index); } if (plot != null && plot instanceof XYPlot) { XYPlot xyPlot = (XYPlot) plot; ValueAxis domainAxis = xyPlot.getDomainAxis(); ValueAxis rangeAxis = xyPlot.getRangeAxis(); // had to switch to SWT's rectangle here. Rectangle screenArea = this.scale(info.getDataArea()); double hotspotSizeX = hotspontsize * this.getScaleX(); double hotspotSizeY = hotspontsize * this.getScaleY(); double x0 = point.getX(); double y0 = point.getY(); double x1 = x0 - hotspotSizeX; double y1 = y0 + hotspotSizeY; double x2 = x0 + hotspotSizeX; double y2 = y0 - hotspotSizeY; RectangleEdge xEdge = RectangleEdge.BOTTOM; RectangleEdge yEdge = RectangleEdge.LEFT; // Switch everything for horizontal charts if (xyPlot.getOrientation() == PlotOrientation.HORIZONTAL) { hotspotSizeX = hotspontsize * this.getScaleY(); hotspotSizeY = hotspontsize * this.getScaleX(); x0 = point.getY(); y0 = point.getX(); x1 = x0 + hotspotSizeX; y1 = y0 - hotspotSizeY; x2 = x0 - hotspotSizeX; y2 = y0 + hotspotSizeY; xEdge = RectangleEdge.LEFT; yEdge = RectangleEdge.BOTTOM; } // OK, here we have to get ourselves back into AWT land... Rectangle2D r2d = new Rectangle2D.Double(); r2d.setRect(screenArea.x, screenArea.y, screenArea.width, screenArea.height); double ty0 = rangeAxis.java2DToValue(y0, r2d, yEdge); double tx1 = domainAxis.java2DToValue(x1, r2d, xEdge); double ty1 = rangeAxis.java2DToValue(y1, r2d, yEdge); double tx2 = domainAxis.java2DToValue(x2, r2d, xEdge); double ty2 = rangeAxis.java2DToValue(y2, r2d, yEdge); int datasetCount = xyPlot.getDatasetCount(); for (int datasetIndex = 0; datasetIndex < datasetCount; datasetIndex++) { XYDataset dataset = xyPlot.getDataset(datasetIndex); int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); if (dataset instanceof OHLCDataset) { // This could be optimized to use a binary search for x first for (int item = 0; item < itemCount; item++) { double xValue = dataset.getXValue(series, item); double yValueHi = ((OHLCDataset) dataset).getHighValue(series, item); double yValueLo = ((OHLCDataset) dataset).getLowValue(series, item); // Check hi lo and swap if needed if (yValueHi < yValueLo) { double temp = yValueHi; yValueHi = yValueLo; yValueLo = temp; } // Check if the dataset 'X' value lies between the hotspot (tx1 < xValue < tx2) if (tx1 < xValue && xValue < tx2) { // Check if the cursor 'y' value lies between the high and low (low < ty0 < high) if (yValueLo < ty0 && ty0 < yValueHi) { return hiLoTips.generateToolTip(dataset, series, item); } } } } else { // This could be optimized to use a binary search for x first for (int item = 0; item < itemCount; item++) { double xValue = dataset.getXValue(series, item); double yValue = dataset.getYValue(series, item); // Check if the dataset 'X' value lies between the hotspot (tx1< xValue < tx2) if (tx1 < xValue && xValue < tx2) { // Check if the dataset 'Y' value lies between the hotspot (ty1 < yValue < ty2) if (ty1 < yValue && yValue < ty2) { return xyTips.generateToolTip(dataset, series, item); } } } } } } } return result; }
From source file:com.xilinx.kintex7.DMATrendChart.java
public void makeChart() { series1 = new TimeSeries(seriesLabels[0]); series2 = new TimeSeries(seriesLabels[1]); series3 = new TimeSeries(seriesLabels[2]); dataset = new TimeSeriesCollection(); dataset.addSeries(series1);//from w w w. j a v a2 s .c o m dataset.addSeries(series2); dataset.addSeries(series3); chart = ChartFactory.createTimeSeriesChart(title, "Time", "Throughput(Gbps)", dataset, true, true, false); chart.setBackgroundPaint(bg); final XYPlot plot = chart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(30000.0); // 60 seconds axis = plot.getRangeAxis(); axis.setRange(0.0, 30.0); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); // set the renderer's stroke Stroke stroke = new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL); renderer.setBaseOutlineStroke(stroke); //StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator("{1}", null, null); //renderer.setSeriesToolTipGenerator(0, tt); // label the points NumberFormat format = NumberFormat.getNumberInstance(); format.setMaximumFractionDigits(2); XYItemLabelGenerator generator = new StandardXYItemLabelGenerator( StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format); renderer.setBaseItemLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); plot.setRenderer(renderer); final XYPlot plot1 = chart.getXYPlot(); ValueAxis axis1 = plot1.getDomainAxis(); axis1.setAutoRange(true); axis1.setFixedAutoRange(30000.0); // 60 seconds axis1 = plot.getRangeAxis(); axis1.setRange(0.0, 30.0); plot1.setRenderer(renderer); final XYPlot plot2 = chart.getXYPlot(); ValueAxis axis2 = plot1.getDomainAxis(); axis2.setAutoRange(true); axis2.setFixedAutoRange(30000.0); // 60 seconds axis2 = plot.getRangeAxis(); axis2.setRange(0.0, 30.0); plot2.setRenderer(renderer); }
From source file:edu.umn.ecology.populus.plot.ChartRendererWithOrientatedShapes.java
@Override protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis, CrosshairState crosshairState, EntityCollection entities) {/*from ww w . j av a 2s .co m*/ //Orient the shapes first double graphicsRatio = dataArea.getHeight() / dataArea.getWidth(); double dataRatio = plot.getRangeAxis().getRange().getLength() / plot.getDomainAxis().getRange().getLength(); double ratio = graphicsRatio / dataRatio; bpInfo.updateDirectedSymbolsJFC(this, ratio); //Now call this to do the rest super.drawSecondaryPass(g2, plot, dataset, pass, series, item, domainAxis, dataArea, rangeAxis, crosshairState, entities); }