List of usage examples for org.jfree.chart.plot XYPlot getDomainAxis
public ValueAxis getDomainAxis(int index)
From source file:org.yccheok.jstock.charting.Utils.java
/** * Applying chart theme based on given JFreeChart. * * @param chart the JFreeChart/*from w w w .ja va 2 s. com*/ */ 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); }/* ww w. j a va 2s . co 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:com.rapidminer.gui.plotter.charts.ChartPanelShiftController.java
/** * Returns the ValueAxis for the plot or <code>null</code> if the plot doesn't have one. * // www .j ava2 s. c om * @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:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java
@Override public void getModelCoordinatesInfo(final int xOnScreen, final int yOnScreen, final IDisplaySurface g, final Point positionInPixels, final StringBuilder sb) { final int x = xOnScreen - positionInPixels.x; final int y = yOnScreen - positionInPixels.y; final ChartEntity entity = info.getEntityCollection().getEntity(x, y); // getChart().handleClick(x, y, info); if (entity instanceof XYItemEntity) { final XYDataset data = ((XYItemEntity) entity).getDataset(); final int index = ((XYItemEntity) entity).getItem(); final int series = ((XYItemEntity) entity).getSeriesIndex(); final double xx = data.getXValue(series, index); final double yy = data.getYValue(series, index); final XYPlot plot = (XYPlot) getJFChart().getPlot(); final ValueAxis xAxis = plot.getDomainAxis(series); final ValueAxis yAxis = plot.getRangeAxis(series); final boolean xInt = xx % 1 == 0; final boolean yInt = yy % 1 == 0; String xTitle = xAxis.getLabel(); if (StringUtils.isBlank(xTitle)) { xTitle = "X"; }//from w w w. j a v a 2 s . c o m String yTitle = yAxis.getLabel(); if (StringUtils.isBlank(yTitle)) { yTitle = "Y"; } sb.append(xTitle).append(" ").append(xInt ? (int) xx : String.format("%.2f", xx)); sb.append(" | ").append(yTitle).append(" ").append(yInt ? (int) yy : String.format("%.2f", yy)); return; } else if (entity instanceof PieSectionEntity) { final String title = ((PieSectionEntity) entity).getSectionKey().toString(); final PieDataset data = ((PieSectionEntity) entity).getDataset(); final int index = ((PieSectionEntity) entity).getSectionIndex(); final double xx = data.getValue(index).doubleValue(); final boolean xInt = xx % 1 == 0; sb.append(title).append(" ").append(xInt ? (int) xx : String.format("%.2f", xx)); return; } else if (entity instanceof CategoryItemEntity) { final Comparable<?> columnKey = ((CategoryItemEntity) entity).getColumnKey(); final String title = columnKey.toString(); final CategoryDataset data = ((CategoryItemEntity) entity).getDataset(); final Comparable<?> rowKey = ((CategoryItemEntity) entity).getRowKey(); final double xx = data.getValue(rowKey, columnKey).doubleValue(); final boolean xInt = xx % 1 == 0; sb.append(title).append(" ").append(xInt ? (int) xx : String.format("%.2f", xx)); return; } }
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 ww. jav 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); }