List of usage examples for org.jfree.chart.plot XYPlot getRangeAxis
public ValueAxis getRangeAxis()
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
public static JFreeChart createBlockingBarChart(String title, HistogramDataset dataset) { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart chart = ChartFactory.createHistogram(null, title, "Key frequency", dataset, //$NON-NLS-1$ PlotOrientation.VERTICAL, false, true, false); XYPlot plot = chart.getXYPlot(); plot.getRangeAxis().setUpperMargin(0.08); // plot.getRangeAxis().setLowerBound(-0.08); decorateCategoryPlot(chart);/*from w w w . ja v a 2 s . c o m*/ plot.setRangeGridlinesVisible(true); XYBarRenderer renderer = new XYBarRenderer() { private static final long serialVersionUID = 4168794048090452033L; @Override public Paint getItemPaint(int row, int column) { return ChartDecorator.COLOR_LIST.get(0); } }; renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); renderer.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); renderer.setShadowVisible(Boolean.FALSE); plot.setRenderer(renderer); return chart; }
From source file:org.jfree.chart.demo.DeviationRendererDemo3.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart chart = ChartFactory.createXYLineChart("DeviationRenderer - Demo 3", "X", "Y", xydataset, PlotOrientation.VERTICAL, false, true, false); XYPlot plot = (XYPlot) chart.getPlot(); ///*from w w w. j av a 2 s.co m*/ DeviationRenderer renderer = new DeviationRenderer(false, false); renderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1)); renderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1)); renderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1)); renderer.setSeriesFillPaint(0, Color.red); renderer.setSeriesFillPaint(1, Color.orange); renderer.setSeriesFillPaint(2, Color.green); plot.setRenderer(renderer); // DateAxis domainAxis = new DateAxis("Date"); domainAxis.setLowerMargin(0.0D); domainAxis.setUpperMargin(0.0D); plot.setDomainAxis(domainAxis); NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis(); valueAxis.setRange(-40D, 40D); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); ChartUtilities.applyCurrentTheme(chart); return chart; }
From source file:org.jfree.chart.demo.BubbleChartDemo2.java
private static JFreeChart createChart(XYZDataset xyzdataset) { JFreeChart jfreechart = ChartFactory.createBubbleChart("Bubble Chart Demo 2", "X", "Y", xyzdataset, PlotOrientation.VERTICAL, true, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setRenderer(new XYBubbleRenderer(0)); xyplot.setForegroundAlpha(0.65F);/* w ww.j ava2 s . co m*/ XYItemRenderer xyitemrenderer = xyplot.getRenderer(); xyitemrenderer.setSeriesPaint(0, Color.blue); xyitemrenderer.setBaseItemLabelGenerator(new BubbleXYItemLabelGenerator()); xyitemrenderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); xyitemrenderer.setBaseItemLabelsVisible(true); xyitemrenderer .setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER)); NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis(); numberaxis.setRange(0.0D, 10D); NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis(); numberaxis1.setRange(0.0D, 10D); return jfreechart; }
From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java
/** * Zoom in (negative yzoom) or zoom out of range axis. * // w w w . j a v a2 s .c om * @param myChart * @param yzoom percentage zoom factor * @param holdLowerBound if true only the upper bound will be zoomed */ public static void zoomRangeAxis(ChartViewer myChart, double yzoom, boolean holdLowerBound) { XYPlot plot = (XYPlot) myChart.getChart().getPlot(); ValueAxis rangeAxis = plot.getRangeAxis(); double lower = rangeAxis.getLowerBound(); double upper = rangeAxis.getUpperBound(); double dist = upper - lower; if (holdLowerBound) { upper += dist * yzoom; } else { lower -= dist * yzoom / 2; upper += dist * yzoom / 2; } if (lower < upper) { Range range = new Range(lower, upper); setZoomAxis(rangeAxis, keepRangeWithinAutoBounds(rangeAxis, range)); } }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIHelper.java
/*********************************************************************************************** * Draw the Chart Crosshair values on the XYPlot if possible. * Used by refreshChart()./*from w w w . j a v a2s . c o m*/ * This should be followed by fireChartChanged() when all updates are complete. * * @param chartui * @param debug */ public static void drawChartCrosshairsOnXYPlot(final ChartUIComponentPlugin chartui, final boolean debug) { final String SOURCE = "ChartHelper.drawChartCrosshairsOnXYPlot() "; // RangeCrosshair if ((chartui != null) && (chartui.getRangeCrosshair() > ChartUIComponentPlugin.RANGE_MIN) && (chartui.getChartPanel() != null) && (chartui.getChartPanel().getChart() != null) && (chartui.getChartPanel().getChart().getXYPlot() != null)) { final XYPlot plot; final ValueAxis rangeAxis; final Range range; final double dblPositionFraction; final double dblRangeCrosshairXYPlot; plot = (XYPlot) chartui.getChartPanel().getChart().getPlot(); rangeAxis = plot.getRangeAxis(); range = rangeAxis.getRange(); dblPositionFraction = (chartui.getRangeCrosshair() - ChartUIComponentPlugin.RANGE_MIN) / (double) (ChartUIComponentPlugin.RANGE_MAX - ChartUIComponentPlugin.RANGE_MIN); dblRangeCrosshairXYPlot = rangeAxis.getLowerBound() + (dblPositionFraction * range.getLength()); FrameworkSingletons.LOGGER.debug(debug, SOURCE + "Draw Range Crosshair on XYPlot [crosshair.range=" + chartui.getRangeCrosshair() + "] [crosshair.xyplot=" + dblRangeCrosshairXYPlot + "] [range.min=" + ChartUIComponentPlugin.RANGE_MIN + "] [range.max=" + ChartUIComponentPlugin.RANGE_MAX + "]"); plot.setRangeCrosshairValue(dblRangeCrosshairXYPlot); } // DomainCrosshair if ((chartui != null) && (chartui.getDomainCrosshair() > ChartUIComponentPlugin.DOMAIN_MIN) && (chartui.getChartPanel() != null) && (chartui.getChartPanel().getChart() != null) && (chartui.getChartPanel().getChart().getXYPlot() != null)) { final XYPlot plot; final ValueAxis domainAxis; final Range range; final double dblPositionFraction; final double dblDomainCrosshairXYPlot; plot = (XYPlot) chartui.getChartPanel().getChart().getPlot(); domainAxis = plot.getDomainAxis(); range = domainAxis.getRange(); // ToDo WARNING! Needs to be the same as for the slider?? dblPositionFraction = (chartui.getDomainCrosshair() - ChartUIComponentPlugin.OFFSET_CONTROL_COARSE_MINIMUM) / (double) (ChartUIComponentPlugin.OFFSET_CONTROL_COARSE_MAXIMUM - ChartUIComponentPlugin.OFFSET_CONTROL_COARSE_MINIMUM); // dblPositionFraction = (chartui.getDomainCrosshair() - ChartUIComponentPlugin.DOMAIN_MIN) / (double)(ChartUIComponentPlugin.DOMAIN_MAX - ChartUIComponentPlugin.DOMAIN_MIN); dblDomainCrosshairXYPlot = domainAxis.getLowerBound() + (dblPositionFraction * range.getLength()); FrameworkSingletons.LOGGER.debug(debug, SOURCE + "Draw Domain Crosshair on XYPlot [crosshair.domain=" + chartui.getDomainCrosshair() + "] [crosshair.xyplot=" + dblDomainCrosshairXYPlot + "] [domain.min=" + ChartUIComponentPlugin.OFFSET_CONTROL_COARSE_MINIMUM + "] [domain.max=" + ChartUIComponentPlugin.OFFSET_CONTROL_COARSE_MAXIMUM + "]"); // LOGGER.debug(debug, // SOURCE + "Draw Domain Crosshair on XYPlot [crosshair.domain=" + chartui.getDomainCrosshair() // + "] [crosshair.xyplot=" + dblDomainCrosshairXYPlot // + "] [domain.min=" + ChartUIComponentPlugin.DOMAIN_MIN // + "] [domain.max=" + ChartUIComponentPlugin.DOMAIN_MAX // + "]"); // plot.setDomainCrosshairValue(dblDomainCrosshairXYPlot); } }
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * Auto range the range axis/* w w w. jav a 2 s. c o m*/ * * @param myChart * @param zoom * @param autoRangeY if true the range (Y) axis auto bounds will be restored */ public static void autoRangeAxis(ChartPanel myChart) { XYPlot plot = (XYPlot) myChart.getChart().getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); // trick. Otherwise auto range will fail sometimes rangeAxis.setRange(rangeAxis.getRange()); rangeAxis.setAutoRangeIncludesZero(true); myChart.restoreAutoRangeBounds(); }
From source file:com.orsonpdf.demo.PDFTimeSeriesChartDemo1.java
/** * Creates a chart.//from ww w. j a va 2s . co m * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("International Coffee Organisation : Coffee Prices", null, "US cents/lb", dataset, true, false, false); String fontName = "Palatino"; chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18)); chart.addSubtitle(new TextTitle("Source: http://www.ico.org/historical/2010-19/PDF/HIST-PRICES.pdf", new Font(fontName, Font.PLAIN, 14))); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(false); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.setRangeGridlinePaint(Color.red); plot.setDomainGridlinePaint(Color.red); chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14)); chart.getLegend().setFrame(BlockBorder.NONE); chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(false); renderer.setDrawSeriesLineAsPath(true); // set the default stroke for all series renderer.setAutoPopulateSeriesStroke(false); renderer.setBaseStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL), false); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesPaint(1, new Color(24, 123, 58)); renderer.setSeriesPaint(2, new Color(149, 201, 136)); renderer.setSeriesPaint(3, new Color(1, 62, 29)); renderer.setSeriesPaint(4, new Color(81, 176, 86)); renderer.setSeriesPaint(5, new Color(0, 55, 122)); renderer.setSeriesPaint(6, new Color(0, 92, 165)); } return chart; }
From source file:org.jfree.graphics2d.demo.SVGTimeSeriesChartDemo1.java
/** * Creates a chart.//from w ww. j a va2s .com * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("International Coffee Organisation : Coffee Prices", null, "US cents/lb", dataset); String fontName = "Palatino"; chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18)); chart.addSubtitle(new TextTitle("Source: http://www.ico.org/historical/2010-19/PDF/HIST-PRICES.pdf", new Font(fontName, Font.PLAIN, 14))); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(false); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.setRangeGridlinePaint(Color.GRAY); plot.setDomainGridlinePaint(Color.GRAY); chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14)); chart.getLegend().setFrame(BlockBorder.NONE); chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(false); renderer.setDrawSeriesLineAsPath(true); // set the default stroke for all series renderer.setAutoPopulateSeriesStroke(false); renderer.setDefaultStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL), false); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesPaint(1, new Color(24, 123, 58)); renderer.setSeriesPaint(2, new Color(149, 201, 136)); renderer.setSeriesPaint(3, new Color(1, 62, 29)); renderer.setSeriesPaint(4, new Color(81, 176, 86)); renderer.setSeriesPaint(5, new Color(0, 55, 122)); renderer.setSeriesPaint(6, new Color(0, 92, 165)); } return chart; }
From source file:eu.cassandra.training.utils.ChartUtils.java
/** * This function is used for parsing and presenting the basic and the new * pricing schema./*w w w. j av a 2 s . co m*/ * * @param basic * The basic pricing schema * @param after * The new pricing schema * * @return a chart panel with the * graphical representation. */ public static ChartPanel parsePricingScheme(String basic, String after) { double[] data = Utils.parseScheme(basic); double[] data2 = Utils.parseScheme(after); XYSeries series1 = new XYSeries("Basic Pricing Scheme"); for (int i = 0; i < data.length; i++) { series1.add(i, data[i]); } XYSeries series2 = new XYSeries("New Pricing Scheme"); for (int i = 0; i < data2.length; i++) { series2.add(i, data2[i]); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = true; boolean toolTips = false; boolean urls = false; JFreeChart chart = ChartFactory.createXYLineChart("Pricing Schemes", "Minute of Day", "Euros/kWh", dataset, orientation, show, toolTips, urls); XYPlot xyplot = (XYPlot) chart.getPlot(); xyplot.setDomainPannable(true); xyplot.setRangePannable(true); xyplot.setForegroundAlpha(0.85F); NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis(); domainAxis.setTickUnit(new NumberTickUnit(100)); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return new ChartPanel(chart); }
From source file:org.jfree.chart.demo.DeviationRendererDemo2.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("Projected Values - Test", "Date", "Index Projection", xydataset, true, true, false); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setInsets(new RectangleInsets(5D, 5D, 5D, 20D)); plot.setBackgroundPaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); ////from w ww . j a v a 2 s . co m DeviationRenderer renderer = new DeviationRenderer(true, false); renderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1)); renderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1)); renderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1)); renderer.setSeriesFillPaint(0, new Color(255, 200, 200)); renderer.setSeriesFillPaint(1, new Color(200, 200, 255)); plot.setRenderer(renderer); // NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis(); valueAxis.setAutoRangeIncludesZero(false); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }