List of usage examples for org.jfree.chart.plot XYPlot getDomainAxisCount
public int getDomainAxisCount()
From source file:net.sf.jsfcomp.chartcreator.utils.ChartAxisUtils.java
public static void createXYSeriesAxis(JFreeChart chart, ChartAxisData chartAxisData, int axisIndex) { ValueAxis axis = null;//from w w w. ja va 2 s . c o m if (chartAxisData.getType() != null) { if (chartAxisData.getType().equals("number")) axis = createNumberAxis(chart, chartAxisData); else if (chartAxisData.getType().equals("date")) axis = createDateAxis(chart, chartAxisData); if (chartAxisData.getTickLabelFontSize() > 0) { Font tickFont = CategoryAxis.DEFAULT_TICK_LABEL_FONT .deriveFont(chartAxisData.getTickLabelFontSize()); axis.setTickLabelFont(tickFont); } axis.setTickLabelsVisible(chartAxisData.isTickLabels()); axis.setTickMarksVisible(chartAxisData.isTickMarks()); axis.setVerticalTickLabels(chartAxisData.isVerticalTickLabels()); } XYPlot plot = chart.getXYPlot(); if (chartAxisData.isDomain()) { plot.setDomainAxis(plot.getDomainAxisCount() - 1, axis); } else { plot.setRangeAxis(axisIndex, axis); XYDataset dataset = (XYDataset) chartAxisData.getDatasource(); plot.setRenderer(axisIndex, new StandardXYItemRenderer()); plot.setDataset(axisIndex, dataset); plot.mapDatasetToRangeAxis(axisIndex, axisIndex); } setXYSeriesAxisColors(chartAxisData, plot.getRenderer(axisIndex)); }
From source file:org.yccheok.jstock.charting.Utils.java
/** * Applying chart theme based on given JFreeChart. * * @param chart the JFreeChart/*from w w w .j a va2 s . c o m*/ */ public static void applyChartTheme(JFreeChart chart) { final StandardChartTheme chartTheme = (StandardChartTheme) org.jfree.chart.StandardChartTheme .createJFreeTheme(); chartTheme.setXYBarPainter(barPainter); chartTheme.setShadowVisible(false); chartTheme.setPlotBackgroundPaint(Color.WHITE); chartTheme.setDomainGridlinePaint(Color.LIGHT_GRAY); chartTheme.setRangeGridlinePaint(Color.LIGHT_GRAY); chartTheme.setPlotOutlinePaint(Color.LIGHT_GRAY); // The default font used by JFreeChart unable to render Chinese properly. // We need to provide font which is able to support Chinese rendering. final Locale defaultLocale = Locale.getDefault(); if (org.yccheok.jstock.gui.Utils.isSimplifiedChinese(defaultLocale) || org.yccheok.jstock.gui.Utils.isTraditionalChinese(defaultLocale)) { final Font oldExtraLargeFont = chartTheme.getExtraLargeFont(); final Font oldLargeFont = chartTheme.getLargeFont(); final Font oldRegularFont = chartTheme.getRegularFont(); final Font oldSmallFont = chartTheme.getSmallFont(); final Font extraLargeFont = new Font("Sans-serif", oldExtraLargeFont.getStyle(), oldExtraLargeFont.getSize()); final Font largeFont = new Font("Sans-serif", oldLargeFont.getStyle(), oldLargeFont.getSize()); final Font regularFont = new Font("Sans-serif", oldRegularFont.getStyle(), oldRegularFont.getSize()); final Font smallFont = new Font("Sans-serif", oldSmallFont.getStyle(), oldSmallFont.getSize()); chartTheme.setExtraLargeFont(extraLargeFont); chartTheme.setLargeFont(largeFont); chartTheme.setRegularFont(regularFont); chartTheme.setSmallFont(smallFont); } if (chart.getPlot() instanceof CombinedDomainXYPlot) { @SuppressWarnings("unchecked") List<Plot> plots = ((CombinedDomainXYPlot) chart.getPlot()).getSubplots(); for (Plot plot : plots) { final int domainAxisCount = ((XYPlot) plot).getDomainAxisCount(); final int rangeAxisCount = ((XYPlot) plot).getRangeAxisCount(); for (int i = 0; i < domainAxisCount; i++) { ((XYPlot) plot).getDomainAxis(i).setAxisLinePaint(Color.LIGHT_GRAY); ((XYPlot) plot).getDomainAxis(i).setTickMarkPaint(Color.LIGHT_GRAY); } for (int i = 0; i < rangeAxisCount; i++) { ((XYPlot) plot).getRangeAxis(i).setAxisLinePaint(Color.LIGHT_GRAY); ((XYPlot) plot).getRangeAxis(i).setTickMarkPaint(Color.LIGHT_GRAY); } } } else { final Plot plot = chart.getPlot(); if (plot instanceof XYPlot) { final org.jfree.chart.plot.XYPlot xyPlot = (org.jfree.chart.plot.XYPlot) plot; final int domainAxisCount = xyPlot.getDomainAxisCount(); final int rangeAxisCount = xyPlot.getRangeAxisCount(); for (int i = 0; i < domainAxisCount; i++) { xyPlot.getDomainAxis(i).setAxisLinePaint(Color.LIGHT_GRAY); xyPlot.getDomainAxis(i).setTickMarkPaint(Color.LIGHT_GRAY); } for (int i = 0; i < rangeAxisCount; i++) { xyPlot.getRangeAxis(i).setAxisLinePaint(Color.LIGHT_GRAY); xyPlot.getRangeAxis(i).setTickMarkPaint(Color.LIGHT_GRAY); } } //else if (plot instanceof org.jfree.chart.plot.PiePlot) { // final org.jfree.chart.plot.PiePlot piePlot = (org.jfree.chart.plot.PiePlot)plot; // //} } chartTheme.apply(chart); }
From source file:mil.tatrc.physiology.utilities.csv.plots.CSVPlotTool.java
public void formatXYPlot(JFreeChart chart, Paint bgColor) { XYPlot plot = (XYPlot) chart.getPlot(); //For Scientific notation NumberFormat formatter = new DecimalFormat("0.######E0"); for (int i = 0; i < plot.getDomainAxisCount(); i++) { plot.getDomainAxis(i).setLabelFont(largeFont); plot.getDomainAxis(i).setTickLabelFont(smallFont); plot.getDomainAxis(i).setLabelPaint(bgColor == Color.red ? Color.white : Color.black); plot.getDomainAxis(i).setTickLabelPaint(bgColor == Color.red ? Color.white : Color.black); }/*from w w w . j av a2 s . c o m*/ for (int i = 0; i < plot.getRangeAxisCount(); i++) { plot.getRangeAxis(i).setLabelFont(largeFont); plot.getRangeAxis(i).setTickLabelFont(smallFont); plot.getRangeAxis(i).setLabelPaint(bgColor == Color.red ? Color.white : Color.black); plot.getRangeAxis(i).setTickLabelPaint(bgColor == Color.red ? Color.white : Color.black); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(i); rangeAxis.setNumberFormatOverride(formatter); } //White background outside of plottable area chart.setBackgroundPaint(bgColor); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinePaint(Color.black); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); chart.getLegend().setItemFont(smallFont); chart.getTitle().setFont(largeFont); chart.getTitle().setPaint(bgColor == Color.red ? Color.white : Color.black); }
From source file:P251.graphPanel.java
/** resizes the axis to the given limits/* ww w . ja v a2 s . c o m*/ */ public void resizeAxis(double d0, double d1, double r0, double r1) { XYPlot plot = (XYPlot) chart.getChart().getPlot(); plot.getDomainAxis().setAutoRange(false); plot.getDomainAxis().setRange(d0, d1); plot.getRangeAxis().setAutoRange(false); plot.getRangeAxis().setRange(r0, r1); System.out.println(plot.getDomainAxisCount()); System.out.println(plot.getRangeAxisCount()); // plot.getRangeAxis().setDefaultAutoRange(new Range(0,1)); }
From source file:com.rapidminer.gui.plotter.charts.ChartPanelShiftController.java
/** * Returns the ValueAxis for the plot or <code>null</code> if the plot doesn't have one. * /*from w ww . j a v a 2 s . c o m*/ * @param chart * The chart * @param domain * True = get Domain axis. False = get Range axis. * @return The selected ValueAxis or <code>null</code> if the plot doesn't have one. */ protected ValueAxis[] getPlotAxis(JFreeChart chart, boolean domain) { // Where's the Shiftable interface when we need it ?? ;) Plot plot = chart.getPlot(); if (plot instanceof XYPlot) { XYPlot xyPlot = (XYPlot) plot; // return domain ? ((XYPlot) plot).getDomainAxis() : ((XYPlot) plot).getRangeAxis(); if (domain) { ValueAxis[] rangeAxes = new ValueAxis[xyPlot.getDomainAxisCount()]; for (int i = 0; i < rangeAxes.length; i++) { rangeAxes[i] = xyPlot.getDomainAxis(i); } return rangeAxes; } else { ValueAxis[] rangeAxes = new ValueAxis[xyPlot.getRangeAxisCount()]; for (int i = 0; i < rangeAxes.length; i++) { rangeAxes[i] = xyPlot.getRangeAxis(i); } return rangeAxes; } } if (plot instanceof FastScatterPlot) { return domain ? new ValueAxis[] { ((FastScatterPlot) plot).getDomainAxis() } : new ValueAxis[] { ((FastScatterPlot) plot).getRangeAxis() }; } return null; }
From source file:mil.tatrc.physiology.utilities.csv.plots.RespiratoryPFTPlotter.java
public void formatRPFTPlot(PlotJob job, JFreeChart chart) { XYPlot plot = (XYPlot) chart.getPlot(); //For Scientific notation NumberFormat formatter = new DecimalFormat("0.######E0"); for (int i = 0; i < plot.getDomainAxisCount(); i++) { plot.getDomainAxis(i).setLabelFont(new Font("SansSerif", Font.PLAIN, job.fontSize)); plot.getDomainAxis(i).setTickLabelFont(new Font("SansSerif", Font.PLAIN, 15)); plot.getDomainAxis(i).setLabelPaint(job.bgColor == Color.red ? Color.white : Color.black); plot.getDomainAxis(i).setTickLabelPaint(job.bgColor == Color.red ? Color.white : Color.black); }//from w w w. j a v a 2 s . c o m for (int i = 0; i < plot.getRangeAxisCount(); i++) { plot.getRangeAxis(i).setLabelFont(new Font("SansSerif", Font.PLAIN, job.fontSize)); plot.getRangeAxis(i).setTickLabelFont(new Font("SansSerif", Font.PLAIN, 15)); plot.getRangeAxis(i).setLabelPaint(job.bgColor == Color.red ? Color.white : Color.black); plot.getRangeAxis(i).setTickLabelPaint(job.bgColor == Color.red ? Color.white : Color.black); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(i); rangeAxis.setNumberFormatOverride(formatter); } //White background outside of plottable area chart.setBackgroundPaint(job.bgColor); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinePaint(Color.black); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 15)); chart.getTitle().setFont(new Font("SansSerif", Font.PLAIN, job.fontSize)); chart.getTitle().setPaint(job.bgColor == Color.red ? Color.white : Color.black); }
From source file:edu.wisc.ssec.mcidasv.control.McIDASVHistogramWrapper.java
/** * reset the histogram to its previous range *///from ww w. j av a2 s. c o m public void resetPlot() { if (chart == null) { return; } if (!(chart.getPlot() instanceof XYPlot)) { return; } XYPlot plot = (XYPlot) chart.getPlot(); int rcnt = plot.getRangeAxisCount(); for (int i = 0; i < rcnt; i++) { ValueAxis axis = plot.getRangeAxis(i); axis.setAutoRange(true); } int dcnt = plot.getDomainAxisCount(); for (int i = 0; i < dcnt; i++) { ValueAxis axis = plot.getDomainAxis(i); try { axis.setRange(low, high); } catch (Exception e) { logger.warn("jfreechart does not like ranges to be high -> low", e); } } }
From source file:mil.tatrc.physiology.utilities.csv.plots.MultiPlotter.java
protected void formatMultiPlot(PlotJob job, JFreeChart chart, XYSeriesCollection dataSet1, XYSeriesCollection dataSet2) {/*w w w .j a v a 2 s . c om*/ Color[] blueColors = { Color.blue, Color.cyan, new Color(0, 160, 255), new Color(0, 100, 255), new Color(0, 160, 255), new Color(14, 0, 145), new Color(70, 105, 150) }; Color[] redColors = { Color.red, Color.magenta, new Color(255, 0, 100), new Color(255, 0, 160), Color.pink, new Color(145, 0, 0), new Color(132, 58, 58) }; Color[] variedColors = { Color.red, Color.blue, Color.green, Color.orange, Color.magenta, Color.cyan, Color.gray, new Color(255, 165, 0), new Color(42, 183, 136), new Color(87, 158, 186) }; XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer1 = (XYLineAndShapeRenderer) plot.getRenderer(); BasicStroke wideLine = new BasicStroke(2.0f); //For Scientific notation NumberFormat formatter = new DecimalFormat("0.######E0"); for (int i = 0; i < plot.getDomainAxisCount(); i++) { plot.getDomainAxis(i).setLabelFont(new Font("SansSerif", Font.PLAIN, job.fontSize)); plot.getDomainAxis(i).setTickLabelFont(new Font("SansSerif", Font.PLAIN, 15)); plot.getDomainAxis(i).setLabelPaint(job.bgColor == Color.red ? Color.white : Color.black); plot.getDomainAxis(i).setTickLabelPaint(job.bgColor == Color.red ? Color.white : Color.black); } for (int i = 0; i < plot.getRangeAxisCount(); i++) { plot.getRangeAxis(i).setLabelFont(new Font("SansSerif", Font.PLAIN, job.fontSize)); plot.getRangeAxis(i).setTickLabelFont(new Font("SansSerif", Font.PLAIN, 15)); plot.getRangeAxis(i).setLabelPaint(job.bgColor == Color.red ? Color.white : Color.black); plot.getRangeAxis(i).setTickLabelPaint(job.bgColor == Color.red ? Color.white : Color.black); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(i); rangeAxis.setNumberFormatOverride(formatter); } //White background outside of plottable area chart.setBackgroundPaint(job.bgColor); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinePaint(Color.black); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 15)); chart.getTitle().setFont(new Font("SansSerif", Font.PLAIN, job.fontSize)); chart.getTitle().setPaint(job.bgColor == Color.red ? Color.white : Color.black); //If there is only one Y axis, we just need to color the data series differently if (job.Y2headers == null || job.Y2headers.isEmpty()) { for (int i = 0, cIndex = 0; i < dataSet1.getSeriesCount(); i++, cIndex++) { renderer1.setSeriesStroke(i, wideLine); renderer1.setBaseShapesVisible(false); if (cIndex > 9) cIndex = 0; renderer1.setSeriesFillPaint(i, variedColors[cIndex]); renderer1.setSeriesPaint(i, variedColors[cIndex]); } } //If there are 2 Y axes, we should color the axes to correspond with the data so it isn't (as) confusing else { StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); plot.setRenderer(1, renderer2); for (int i = 0, cIndex = 0; i < dataSet1.getSeriesCount(); i++, cIndex++) { renderer1.setSeriesStroke(i, wideLine); renderer1.setBaseShapesVisible(false); if (cIndex > 6) cIndex = 0; renderer1.setSeriesFillPaint(i, redColors[cIndex]); renderer1.setSeriesPaint(i, redColors[cIndex]); } for (int i = 0, cIndex = 0; i < dataSet2.getSeriesCount(); i++, cIndex++) { renderer2.setSeriesStroke(i, wideLine); renderer2.setBaseShapesVisible(false); if (cIndex > 6) cIndex = 0; renderer2.setSeriesFillPaint(i, blueColors[cIndex]); renderer2.setSeriesPaint(i, blueColors[cIndex]); } plot.getRangeAxis(0).setLabelPaint(redColors[0]); plot.getRangeAxis(0).setTickLabelPaint(redColors[0]); plot.getRangeAxis(1).setLabelPaint(blueColors[0]); plot.getRangeAxis(1).setTickLabelPaint(blueColors[0]); } }
From source file:mil.tatrc.physiology.utilities.csv.plots.ConvexHullPlotter.java
protected void formatConvexHullPlot(PlotJob job, JFreeChart chart, XYSeriesCollection dataSet1, XYSeriesCollection dataSet2) {/* w w w .j a va 2s. c om*/ XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer1 = (XYLineAndShapeRenderer) plot.getRenderer(); BasicStroke wideLine = new BasicStroke(2.0f); //For Scientific notation NumberFormat formatter = new DecimalFormat("0.######E0"); for (int i = 0; i < plot.getDomainAxisCount(); i++) { plot.getDomainAxis(i).setLabelFont(new Font("SansSerif", Font.PLAIN, job.fontSize)); plot.getDomainAxis(i).setTickLabelFont(new Font("SansSerif", Font.PLAIN, 15)); plot.getDomainAxis(i).setLabelPaint(job.bgColor == Color.red ? Color.white : Color.black); plot.getDomainAxis(i).setTickLabelPaint(job.bgColor == Color.red ? Color.white : Color.black); } for (int i = 0; i < plot.getRangeAxisCount(); i++) { plot.getRangeAxis(i).setLabelFont(new Font("SansSerif", Font.PLAIN, job.fontSize)); plot.getRangeAxis(i).setTickLabelFont(new Font("SansSerif", Font.PLAIN, 15)); plot.getRangeAxis(i).setLabelPaint(job.bgColor == Color.red ? Color.white : Color.black); plot.getRangeAxis(i).setTickLabelPaint(job.bgColor == Color.red ? Color.white : Color.black); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(i); rangeAxis.setNumberFormatOverride(formatter); } //White background outside of plottable area chart.setBackgroundPaint(job.bgColor); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinePaint(Color.black); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 15)); chart.getTitle().setFont(new Font("SansSerif", Font.PLAIN, job.fontSize)); chart.getTitle().setPaint(job.bgColor == Color.red ? Color.white : Color.black); //If there is only one Y axis, color all datasets red (so top, bottom, left, and right will be the same) if (job.Y2headers == null || job.Y2headers.isEmpty()) { for (int i = 0; i < dataSet1.getSeriesCount(); i++) { renderer1.setSeriesStroke(i, wideLine); renderer1.setBaseShapesVisible(false); renderer1.setSeriesFillPaint(i, Color.red); renderer1.setSeriesPaint(i, Color.red); if (dataSet1.getSeries(i).getKey() != null && dataSet1.getSeries(i).getKey().toString().equalsIgnoreCase("REMOVE")) renderer1.setSeriesVisibleInLegend(i, false); } } //If there are 2 Y axes, we should color the axes to correspond with the data so it isn't (as) confusing else { StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); plot.setRenderer(1, renderer2); for (int i = 0; i < dataSet1.getSeriesCount(); i++) { renderer1.setSeriesStroke(i, wideLine); renderer1.setBaseShapesVisible(false); renderer1.setSeriesFillPaint(i, Color.red); renderer1.setSeriesPaint(i, Color.red); if (dataSet1.getSeries(i).getKey() != null && dataSet1.getSeries(i).getKey().toString().equalsIgnoreCase("REMOVE")) renderer1.setSeriesVisibleInLegend(i, false); } for (int i = 0; i < dataSet2.getSeriesCount(); i++) { renderer2.setSeriesStroke(i, wideLine); renderer2.setBaseShapesVisible(false); renderer2.setSeriesFillPaint(i, Color.blue); renderer2.setSeriesPaint(i, Color.blue); if (dataSet2.getSeries(i).getKey() != null && dataSet2.getSeries(i).getKey().toString().equalsIgnoreCase("REMOVE")) renderer2.setSeriesVisibleInLegend(i, false); } plot.getRangeAxis(0).setLabelPaint(Color.red); plot.getRangeAxis(0).setTickLabelPaint(Color.red); plot.getRangeAxis(1).setLabelPaint(Color.blue); plot.getRangeAxis(1).setTickLabelPaint(Color.blue); } }
From source file:mil.tatrc.physiology.utilities.csv.plots.ActionEventPlotter.java
public void formatAEPlot(PlotJob job, JFreeChart chart) { XYPlot plot = (XYPlot) chart.getPlot(); //For Scientific notation NumberFormat formatter = new DecimalFormat("0.######E0"); for (int i = 0; i < plot.getDomainAxisCount(); i++) { plot.getDomainAxis(i).setLabelFont(new Font("SansSerif", Font.PLAIN, job.fontSize)); plot.getDomainAxis(i).setTickLabelFont(new Font("SansSerif", Font.PLAIN, 15)); plot.getDomainAxis(i).setLabelPaint(job.bgColor == Color.red ? Color.white : Color.black); plot.getDomainAxis(i).setTickLabelPaint(job.bgColor == Color.red ? Color.white : Color.black); }/* ww w . j ava2s . c o m*/ for (int i = 0; i < plot.getRangeAxisCount(); i++) { plot.getRangeAxis(i).setLabelFont(new Font("SansSerif", Font.PLAIN, job.fontSize)); plot.getRangeAxis(i).setTickLabelFont(new Font("SansSerif", Font.PLAIN, 15)); plot.getRangeAxis(i).setLabelPaint(job.bgColor == Color.red ? Color.white : Color.black); plot.getRangeAxis(i).setTickLabelPaint(job.bgColor == Color.red ? Color.white : Color.black); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(i); rangeAxis.setNumberFormatOverride(formatter); } //White background outside of plottable area chart.setBackgroundPaint(job.bgColor); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinePaint(Color.black); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 15)); chart.getTitle().setFont(new Font("SansSerif", Font.PLAIN, job.fontSize)); chart.getTitle().setPaint(job.bgColor == Color.red ? Color.white : Color.black); }