List of usage examples for org.jfree.chart.axis NumberAxis setLabelFont
public void setLabelFont(Font font)
From source file:unalcol.termites.boxplots.RoundNumberGlobal.java
/** * Creates a new demo.//from ww w .j a va 2 s . c om * * @param title the frame title. * @param pf */ public RoundNumberGlobal(final String title, ArrayList<Double> pf) { super(title); final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf); final CategoryAxis xAxis = new CategoryAxis(""); //final NumberAxis yAxis = new NumberAxis("Round number"); final NumberAxis yAxis = new NumberAxis(""); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 16); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Round Number" + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setFont(font); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); chart.getLegend().setItemFont(font); FileOutputStream output; try { output = new FileOutputStream("roundGlobalNumber" + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null); } catch (FileNotFoundException ex) { Logger.getLogger(RoundNumberGlobal.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(RoundNumberGlobal.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.rapidminer.gui.plotter.charts.BarChartPlotter.java
@Override public void updatePlotter() { final int categoryCount = prepareData(); SwingUtilities.invokeLater(new Runnable() { @Override/*from w w w . ja v a 2s .c om*/ public void run() { scrollablePlotterPanel.remove(viewScrollBar); } }); CategoryDataset usedCategoryDataSet = categoryDataSet; if (categoryCount > MAX_CATEGORY_VIEW_COUNT && showScrollbar) { if (orientationIndex == ORIENTATION_TYPE_VERTICAL) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { viewScrollBar.setOrientation(Adjustable.HORIZONTAL); scrollablePlotterPanel.add(viewScrollBar, BorderLayout.SOUTH); } }); } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { viewScrollBar.setOrientation(Adjustable.VERTICAL); scrollablePlotterPanel.add(viewScrollBar, BorderLayout.EAST); } }); } this.slidingCategoryDataSet = new SlidingCategoryDataset(categoryDataSet, 0, MAX_CATEGORY_VIEW_COUNT); viewScrollBar.setMaximum(categoryCount); viewScrollBar.setValue(0); usedCategoryDataSet = this.slidingCategoryDataSet; } else { this.slidingCategoryDataSet = null; } if (categoryCount <= MAX_CATEGORIES) { JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label usedCategoryDataSet, // data orientationIndex == ORIENTATION_TYPE_VERTICAL ? PlotOrientation.VERTICAL : PlotOrientation.HORIZONTAL, // orientation false, // include legend if group by column is set true, // tooltips false // URLs ); // set the background color for the chart... chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setBackgroundPaint(Color.WHITE); CategoryPlot plot = chart.getCategoryPlot(); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLabelFont(LABEL_FONT_BOLD); domainAxis.setTickLabelFont(LABEL_FONT); String domainName = groupByColumn >= 0 ? dataTable.getColumnName(groupByColumn) : null; domainAxis.setLabel(domainName); // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d)); } // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabelFont(LABEL_FONT_BOLD); rangeAxis.setTickLabelFont(LABEL_FONT); String rangeName = valueColumn >= 0 ? dataTable.getColumnName(valueColumn) : null; rangeAxis.setLabel(rangeName); // bar renderer double[] colorValues = null; if (groupByColumn >= 0 && this.dataTable.isNominal(groupByColumn)) { colorValues = new double[this.dataTable.getNumberOfValues(groupByColumn)]; } else { colorValues = new double[categoryDataSet.getColumnCount()]; } for (int i = 0; i < colorValues.length; i++) { colorValues[i] = i; } BarRenderer renderer = new ColorizedBarRenderer(colorValues); renderer.setBarPainter(new RapidBarPainter()); renderer.setDrawBarOutline(true); int size = categoryDataSet.getRowCount(); if (size > 1) { for (int i = 0; i < size; i++) { renderer.setSeriesPaint(i, getColorProvider(true).getPointColor(i / (double) (size - 1))); } } plot.setRenderer(renderer); // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); } if (panel != null) { panel.setChart(chart); } else { panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN); scrollablePlotterPanel.add(panel, BorderLayout.CENTER); final ChartPanelShiftController controller = new ChartPanelShiftController(panel); panel.addMouseListener(controller); panel.addMouseMotionListener(controller); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); } else { // LogService.getGlobal().logNote("Too many columns (" + categoryCount + // "), this chart is only able to plot up to " + MAX_CATEGORIES + // " different categories."); LogService.getRoot().log(Level.INFO, "com.rapidminer.gui.plotter.charts.BarChartPlotter.too_many_columns", new Object[] { categoryCount, MAX_CATEGORIES }); } }
From source file:org.locationtech.udig.processingtoolbox.tools.BubbleChartDialog.java
private void updateChart(SimpleFeatureCollection features, String xField, String yField, String sizeField) { // 1. Create a single plot containing both the scatter and line XYPlot plot = new XYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainPannable(false);//from ww w . j a v a 2 s . c om plot.setRangePannable(false); plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setForegroundAlpha(0.75f); // 2. Setup Scatter plot // Create the bubble chart data, renderer, and axis int fontStyle = java.awt.Font.BOLD; FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0]; NumberAxis xPlotAxis = new NumberAxis(xField); // Independent variable xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); NumberAxis yPlotAxis = new NumberAxis(yField); // Dependent variable yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); XYItemRenderer plotRenderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); plotRenderer.setSeriesPaint(0, java.awt.Color.ORANGE); // dot plotRenderer.setBaseItemLabelGenerator(new BubbleXYItemLabelGenerator()); plotRenderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); plotRenderer .setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER)); // Set the bubble chart data, renderer, and axis into plot plot.setDataset(0, getBubbleChartData(features, xField, yField, sizeField)); xPlotAxis.setAutoRangeIncludesZero(false); xPlotAxis.setAutoRange(false); double differUpper = minMaxVisitor.getMaxX() - minMaxVisitor.getAverageX(); double differLower = minMaxVisitor.getAverageX() - minMaxVisitor.getMinX(); double gap = Math.abs(differUpper - differLower); if (differUpper > differLower) { xPlotAxis.setRange(minMaxVisitor.getMinX() - gap, minMaxVisitor.getMaxX()); } else { xPlotAxis.setRange(minMaxVisitor.getMinX(), minMaxVisitor.getMaxX() + gap); } yPlotAxis.setAutoRangeIncludesZero(false); yPlotAxis.setAutoRange(false); differUpper = minMaxVisitor.getMaxY() - minMaxVisitor.getAverageY(); differLower = minMaxVisitor.getAverageY() - minMaxVisitor.getMinY(); gap = Math.abs(differUpper - differLower); if (differUpper > differLower) { yPlotAxis.setRange(minMaxVisitor.getMinY() - gap, minMaxVisitor.getMaxY()); } else { yPlotAxis.setRange(minMaxVisitor.getMinY(), minMaxVisitor.getMaxY() + gap); } plot.setRenderer(0, plotRenderer); plot.setDomainAxis(0, xPlotAxis); plot.setRangeAxis(0, yPlotAxis); // Map the scatter to the first Domain and first Range plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); // 3. Setup line // Create the line data, renderer, and axis XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only lineRenderer.setSeriesPaint(0, java.awt.Color.GRAY); lineRenderer.setSeriesPaint(1, java.awt.Color.GRAY); lineRenderer.setSeriesPaint(2, java.awt.Color.GRAY); // Set the line data, renderer, and axis into plot NumberAxis xLineAxis = new NumberAxis(EMPTY); xLineAxis.setTickMarksVisible(false); xLineAxis.setTickLabelsVisible(false); NumberAxis yLineAxis = new NumberAxis(EMPTY); yLineAxis.setTickMarksVisible(false); yLineAxis.setTickLabelsVisible(false); XYSeriesCollection lineDataset = new XYSeriesCollection(); // AverageY XYSeries horizontal = new XYSeries("AverageY"); //$NON-NLS-1$ horizontal.add(xPlotAxis.getRange().getLowerBound(), minMaxVisitor.getAverageY()); horizontal.add(xPlotAxis.getRange().getUpperBound(), minMaxVisitor.getAverageY()); lineDataset.addSeries(horizontal); // AverageX XYSeries vertical = new XYSeries("AverageX"); //$NON-NLS-1$ vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getLowerBound()); vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getUpperBound()); lineDataset.addSeries(vertical); plot.setDataset(1, lineDataset); plot.setRenderer(1, lineRenderer); plot.setDomainAxis(1, xLineAxis); plot.setRangeAxis(1, yLineAxis); // Map the line to the second Domain and second Range plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 0); // 4. Setup Selection NumberAxis xSelectionAxis = new NumberAxis(EMPTY); xSelectionAxis.setTickMarksVisible(false); xSelectionAxis.setTickLabelsVisible(false); NumberAxis ySelectionAxis = new NumberAxis(EMPTY); ySelectionAxis.setTickMarksVisible(false); ySelectionAxis.setTickLabelsVisible(false); XYItemRenderer selectionRenderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot selectionRenderer.setSeriesOutlinePaint(0, java.awt.Color.RED); plot.setDataset(2, new DefaultXYZDataset2()); plot.setRenderer(2, selectionRenderer); plot.setDomainAxis(2, xSelectionAxis); plot.setRangeAxis(2, ySelectionAxis); // Map the scatter to the second Domain and second Range plot.mapDatasetToDomainAxis(2, 0); plot.mapDatasetToRangeAxis(2, 0); // 5. Finally, Create the chart with the plot and a legend java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20); JFreeChart chart = new JFreeChart(EMPTY, titleFont, plot, false); chart.setBackgroundPaint(java.awt.Color.WHITE); chart.setBorderVisible(false); chartComposite.setChart(chart); chartComposite.forceRedraw(); }
From source file:unalcol.termites.boxplots.ECALAgentsRight.java
/** * Creates a new demo./*from www . j a v a 2 s . c o m*/ * * @param title the frame title. * @param pf */ public ECALAgentsRight(final String title, ArrayList<Double> pf) { super(title); final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf); final CategoryAxis xAxis = new CategoryAxis(""); // final NumberAxis yAxis = new NumberAxis("Round number"); final NumberAxis yAxis = new NumberAxis(""); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 13); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Agents Right " + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setFont(font); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); chart.getLegend().setItemFont(font); FileOutputStream output; try { output = new FileOutputStream("ECALright" + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null); } catch (FileNotFoundException ex) { Logger.getLogger(ECALAgentsRight.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ECALAgentsRight.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:unalcol.termites.boxplots.ECALRoundNumber.java
/** * Creates a new demo.//w ww. j a v a 2 s. c om * * @param title the frame title. * @param pf */ public ECALRoundNumber(final String title, ArrayList<Double> pf) { super(title); final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf); final CategoryAxis xAxis = new CategoryAxis(""); // final NumberAxis yAxis = new NumberAxis("Round number"); final NumberAxis yAxis = new NumberAxis(""); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 13); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Round Number " + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setFont(font); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); chart.getLegend().setItemFont(font); FileOutputStream output; try { output = new FileOutputStream("ECALround" + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null); } catch (FileNotFoundException ex) { Logger.getLogger(ECALRoundNumber.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ECALRoundNumber.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:uk.co.moonsit.sockets.GraphClient.java
private NumberAxis getTheRangeAxis(int index) {//, DatasetAndAxis[] dAnda) { //if (dAnda[index].numberAxisObj !=null) { // return dAnda[index].numberAxisObj; //}/* w ww . j a va 2 s . co m*/ NumberAxis rangeAxis; Color axisColor = getAxisColor(index); String axisLabel = "Range"; if (index > 0) { axisLabel += "-" + (index + 1); } rangeAxis = new NumberAxis(axisLabel); rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 9)); rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12)); rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); // rangeAxis.setRange(new Range(0,0)); // need to set a range or we get a NaN on getRange() calls //rangeAxis.setAutoRange(false); rangeAxis.setAutoRangeIncludesZero(false); // set colors rangeAxis.setLabelPaint(axisColor); rangeAxis.setAxisLinePaint(axisColor); rangeAxis.setLabelPaint(axisColor); rangeAxis.setTickLabelPaint(axisColor); rangeAxis.setTickMarkPaint(axisColor); //dAnda[index].numberAxisObj=rangeAxis; return rangeAxis; }
From source file:unalcol.termites.boxplots.RoundNumber2.java
/** * Creates a new demo.//from w w w . j a v a2s . c o m * * @param title the frame title. * @param pf */ public RoundNumber2(final String title, ArrayList<Double> pf) { super(title); final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf); final CategoryAxis xAxis = new CategoryAxis(""); // final NumberAxis yAxis = new NumberAxis("Round number"); final NumberAxis yAxis = new NumberAxis(""); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 13); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Round Number " + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setFont(font); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); chart.getLegend().setItemFont(font); FileOutputStream output; try { output = new FileOutputStream("roundnumber2" + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 300, 250, null); } catch (FileNotFoundException ex) { Logger.getLogger(RoundNumber2.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(RoundNumber2.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:unalcol.termites.boxplots.InformationCollected2.java
/** * Creates a new demo.// w w w. j av a2 s. c om * * @param title the frame title. * @param pf */ public InformationCollected2(final String title, ArrayList<Double> pf) { super(title); final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf); final CategoryAxis xAxis = new CategoryAxis(""); //final NumberAxis yAxis = new NumberAxis("Information Collected"); final NumberAxis yAxis = new NumberAxis(""); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 13); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Information Collected " + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setFont(font); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); chart.getLegend().setItemFont(font); FileOutputStream output; try { output = new FileOutputStream("informationcollected2" + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 350, 350, null); } catch (FileNotFoundException ex) { Logger.getLogger(InformationCollected2.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(InformationCollected2.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:unalcol.termites.boxplots.HybridRoundNumberReport.java
/** * Creates a new demo.//from w w w.j a va 2 s. c o m * * @param title the frame title. * @param pf */ public HybridRoundNumberReport(final String title, ArrayList<Double> pf) { super(title); final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf); final CategoryAxis xAxis = new CategoryAxis(""); //final NumberAxis yAxis = new NumberAxis("Round number"); final NumberAxis yAxis = new NumberAxis(""); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 14); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Round Number" + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setFont(font); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); chart.getLegend().setItemFont(font); FileOutputStream output; try { output = new FileOutputStream("roundnumber1" + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 1350, 400, null); } catch (FileNotFoundException ex) { Logger.getLogger(HybridRoundNumberReport.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(HybridRoundNumberReport.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.ChartAxisFactory.java
public static ValueAxis createRangeAxis(RangeAxisConfig rangeAxisConfig, PlotInstance plotInstance) throws ChartPlottimeException { if (rangeAxisConfig.getValueType() == ValueType.UNKNOWN || rangeAxisConfig.getValueType() == ValueType.INVALID) { return null; } else {/* w w w.ja v a2 s .c o m*/ RangeAxisData rangeAxisData = plotInstance.getPlotData().getRangeAxisData(rangeAxisConfig); double initialUpperBound = rangeAxisData.getUpperViewBound(); double initialLowerBound = rangeAxisData.getLowerViewBound(); double upperBound = initialUpperBound; double lowerBound = initialLowerBound; // fetch old zooming LinkAndBrushMaster linkAndBrushMaster = plotInstance.getMasterPlotConfiguration() .getLinkAndBrushMaster(); Range axisZoom = linkAndBrushMaster.getRangeAxisZoom(rangeAxisConfig, plotInstance.getCurrentPlotConfigurationClone()); List<ValueSource> valueSources = rangeAxisConfig.getValueSources(); if (rangeAxisConfig.hasAbsolutStackedPlot()) { for (ValueSource valueSource : valueSources) { VisualizationType seriesType = valueSource.getSeriesFormat().getSeriesType(); if (seriesType == VisualizationType.BARS || seriesType == VisualizationType.AREA) { if (valueSource.getSeriesFormat().getStackingMode() == StackingMode.ABSOLUTE) { Pair<Double, Double> minMax = calculateUpperAndLowerBounds(valueSource, plotInstance); if (upperBound < minMax.getSecond()) { upperBound = minMax.getSecond(); } if (lowerBound > minMax.getFirst()) { lowerBound = minMax.getFirst(); } } } } } double margin = upperBound - lowerBound; if (lowerBound == upperBound) { margin = lowerBound; } if (margin == 0) { margin = 0.1; } double normalPad = RangeAxisConfig.padFactor * margin; if (rangeAxisConfig.isLogarithmicAxis()) { if (!rangeAxisConfig.isUsingUserDefinedLowerViewBound()) { lowerBound -= RangeAxisConfig.logPadFactor * lowerBound; } if (!rangeAxisConfig.isUsingUserDefinedUpperViewBound()) { upperBound += RangeAxisConfig.logPadFactor * upperBound; } } else { // add margin if (!rangeAxisConfig.isUsingUserDefinedLowerViewBound()) { lowerBound -= normalPad; } if (!rangeAxisConfig.isUsingUserDefinedUpperViewBound()) { upperBound += normalPad; } } boolean includeZero = false; if (isIncludingZero(rangeAxisConfig, initialLowerBound) && !rangeAxisConfig.isUsingUserDefinedLowerViewBound()) { // if so set lower bound to zero lowerBound = 0.0; includeZero = true; } boolean upToOne = false; // if there are only relative plots set upper Bound to 1.0 if (rangeAxisConfig.mustHaveUpperBoundOne(initialUpperBound) && !rangeAxisConfig.isUsingUserDefinedUpperViewBound()) { upperBound = 1.0; upToOne = true; } if (includeZero && !upToOne) { upperBound *= 1.05; } String label = rangeAxisConfig.getLabel(); if (label == null) { label = I18N.getGUILabel("plotter.unnamed_value_label"); } ValueAxis rangeAxis; if (rangeAxisConfig.getValueType() == ValueType.NOMINAL && !valueSources.isEmpty()) { // get union of distinct values of all plotValueConfigs on range axis int maxValue = Integer.MIN_VALUE; for (ValueSource valueSource : rangeAxisData.getRangeAxisConfig().getValueSources()) { ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource); double maxValueInSource = valueSourceData.getMaxValue(); if (maxValueInSource > maxValue) { maxValue = (int) maxValueInSource; } } Vector<String> yValueStrings = new Vector<String>(maxValue); yValueStrings.setSize(maxValue + 1); ValueSourceData valueSourceData = plotInstance.getPlotData() .getValueSourceData(valueSources.get(0)); for (int i = 0; i <= maxValue; ++i) { yValueStrings.set(i, valueSourceData.getStringForValue(SeriesUsageType.MAIN_SERIES, i)); } String[] yValueStringArray = new String[yValueStrings.size()]; int i = 0; for (String s : yValueStrings) { yValueStringArray[i] = s; ++i; } CustomSymbolAxis symbolRangeAxis = new CustomSymbolAxis(null, yValueStringArray); symbolRangeAxis.setVisible(true); symbolRangeAxis.setAutoRangeIncludesZero(false); symbolRangeAxis.saveUpperBound(upperBound, initialUpperBound); symbolRangeAxis.saveLowerBound(lowerBound, initialLowerBound); symbolRangeAxis.setLabel(label); Font axesFont = plotInstance.getCurrentPlotConfigurationClone().getAxesFont(); if (axesFont != null) { symbolRangeAxis.setLabelFont(axesFont); symbolRangeAxis.setTickLabelFont(axesFont); } // set range if axis has been zoomed before if (axisZoom != null) { symbolRangeAxis.setRange(axisZoom); } rangeAxis = symbolRangeAxis; } else if (rangeAxisConfig.getValueType() == ValueType.NUMERICAL) { NumberAxis numberRangeAxis; if (rangeAxisConfig.isLogarithmicAxis()) { if (rangeAxisData.getMinYValue() <= 0) { throw new ChartPlottimeException("log_axis_contains_zero", label); } numberRangeAxis = new CustomLogarithmicAxis(null); ((CustomLogarithmicAxis) numberRangeAxis).saveUpperBound(upperBound, initialUpperBound); ((CustomLogarithmicAxis) numberRangeAxis).saveLowerBound(lowerBound, initialLowerBound); } else { numberRangeAxis = new CustomNumberAxis(); ((CustomNumberAxis) numberRangeAxis).saveUpperBound(upperBound, initialUpperBound); ((CustomNumberAxis) numberRangeAxis).saveLowerBound(lowerBound, initialLowerBound); } numberRangeAxis.setAutoRangeIncludesZero(false); numberRangeAxis.setVisible(true); numberRangeAxis.setLabel(label); Font axesFont = plotInstance.getCurrentPlotConfigurationClone().getAxesFont(); if (axesFont != null) { numberRangeAxis.setLabelFont(axesFont); numberRangeAxis.setTickLabelFont(axesFont); } // set range if axis has been zoomed before if (axisZoom != null) { numberRangeAxis.setRange(axisZoom); } rangeAxis = numberRangeAxis; } else if (rangeAxisConfig.getValueType() == ValueType.DATE_TIME) { CustomDateAxis dateRangeAxis; if (rangeAxisConfig.isLogarithmicAxis()) { throw new ChartPlottimeException("logarithmic_not_supported_for_value_type", label, ValueType.DATE_TIME); } else { dateRangeAxis = new CustomDateAxis(); } dateRangeAxis.saveUpperBound(upperBound, initialUpperBound); dateRangeAxis.saveLowerBound(lowerBound, initialLowerBound); dateRangeAxis.setVisible(true); dateRangeAxis.setLabel(label); Font axesFont = plotInstance.getCurrentPlotConfigurationClone().getAxesFont(); if (axesFont != null) { dateRangeAxis.setLabelFont(axesFont); } // set range if axis has been zoomed before if (axisZoom != null) { dateRangeAxis.setRange(axisZoom); } rangeAxis = dateRangeAxis; } else { throw new RuntimeException("Unknown value type. This should not happen"); } // configure format formatAxis(plotInstance.getCurrentPlotConfigurationClone(), rangeAxis); return rangeAxis; } }