List of usage examples for org.jfree.chart.axis NumberAxis setUpperMargin
public void setUpperMargin(double margin)
From source file:org.jfree.chart.demo.PriceVolumeDemo1.java
private static JFreeChart createChart() { XYDataset xydataset = createPriceDataset(); String s = "Eurodollar Futures Contract (MAR03)"; JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(s, "Date", "Price", xydataset, true, true, false);// w ww . j av a2 s . co m XYPlot xyplot = (XYPlot) jfreechart.getPlot(); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setLowerMargin(0.40000000000000002D); DecimalFormat decimalformat = new DecimalFormat("00.00"); numberaxis.setNumberFormatOverride(decimalformat); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); xyitemrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); NumberAxis numberaxis1 = new NumberAxis("Volume"); numberaxis1.setUpperMargin(1.0D); xyplot.setRangeAxis(1, numberaxis1); xyplot.setDataset(1, createVolumeDataset()); xyplot.setRangeAxis(1, numberaxis1); xyplot.mapDatasetToRangeAxis(1, 1); XYBarRenderer xybarrenderer = new XYBarRenderer(0.20000000000000001D); xybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00"))); xyplot.setRenderer(1, xybarrenderer); return jfreechart; }
From source file:net.commerce.zocalo.freechart.ChartGenerator.java
public static JFreeChart buildBarChart(DefaultCategoryDataset dataset, PlotOrientation orientation, int hSize, int vSize) { JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label dataset, // data orientation, // the plot orientation false, // include legend false, // tooltips false // generate urls );/*from ww w .j a va 2 s . c o m*/ CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA!"); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); plot.setRenderer(renderer); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setUpperMargin(0.15); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(hSize, vSize)); chart.setBackgroundPaint(Color.white); return chart; }
From source file:unalcol.termites.boxplots.SucessfulRates.java
private static JFreeChart createChart(CategoryDataset categorydataset, ArrayList<Double> pf) { JFreeChart jfreechart = ChartFactory.createBarChart("Success Rates - " + getTitle(pf), "", "", categorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.getTitle().setFont(new Font("Sans-Serif", Font.PLAIN, 18)); jfreechart.setBackgroundPaint(new Color(221, 223, 238)); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setDomainGridlinePaint(Color.white); categoryplot.setRangeGridlinePaint(Color.gray); categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); BarRenderer renderer = (BarRenderer) categoryplot.getRenderer(); //categoryplot.setBackgroundPaint(new Color(221, 223, 238)); renderer.setSeriesPaint(0, new Color(130, 165, 70)); renderer.setSeriesPaint(1, new Color(220, 165, 70)); renderer.setSeriesPaint(4, new Color(255, 165, 70)); renderer.setDrawBarOutline(false);//from ww w .j a va2s .co m renderer.setShadowVisible(false); // renderer.setMaximumBarWidth(1); renderer.setGradientPaintTransformer(null); renderer.setDefaultBarPainter(new StandardBarPainter()); categoryplot.setRenderer(renderer); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setUpperMargin(0.25D); CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer(); categoryitemrenderer.setBaseItemLabelsVisible(true); categoryitemrenderer.setBaseItemLabelGenerator(new LabelGenerator(null)); numberaxis.setRange(0, 100); //numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); Font font = new Font("SansSerif", Font.ROMAN_BASELINE, 12); numberaxis.setTickLabelFont(font); CategoryAxis axisd = categoryplot.getDomainAxis(); ValueAxis axisr = categoryplot.getRangeAxis(); axisd.setTickLabelFont(font); axisr.setTickLabelFont(font); final ChartPanel chartPanel = new ChartPanel(jfreechart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); FileOutputStream output; try { output = new FileOutputStream("sucessrates1" + pf + mazeMode + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, jfreechart, 650, 370, null); } catch (FileNotFoundException ex) { Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex); } return jfreechart; }
From source file:com.mxgraph.examples.swing.chart.BarChartDemo1.java
public static JFreeChart createChart1(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("", // chart title "X-value", // domain axis label "Y-value", // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation true, // include legend true, // tooltips? false // URLs? );// www .j a v a 2 s. c o m // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setCategoryMargin(0.1);// categoryAxis.setUpperMargin(0.02); categoryAxis.setLowerMargin(0.02); // ****************************************************************** // More than 150 demo applications are included with the JFreeChart // Developer Guide...for more information, see: // // > http://www.object-refinery.com/jfreechart/guide.html // // ****************************************************************** // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.10); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(true); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); renderer.setItemLabelAnchorOffset(10D); renderer.setItemLabelFont(new Font("", Font.PLAIN, 12)); renderer.setItemLabelsVisible(true); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 180)); // OPTIONAL CUSTOMISATION COMPLETED. chart.getTitle().setFont(new Font("", Font.BOLD, 16));// // domainAxis.setLabelFont(new Font("", Font.BOLD, 14)); // domainAxis.setTickLabelFont(new Font("", Font.PLAIN, 10)); // rangeAxis.setLabelFont(new Font("", Font.BOLD, 15)); chart.getLegend().setItemFont(new Font("", Font.BOLD, 15)); /** * chart.getTitle().setFont(new Font("",Font.BOLD,20));// // domainAxis.setLabelFont(new Font("",Font.BOLD,14)); // domainAxis.setTickLabelFont(new Font("",Font.BOLD,12)); // rangeAxis.setLabelFont(new Font("",Font.BOLD,15)); chart.getLegend().setItemFont(new Font("", Font.BOLD, 15)); */ return chart; }
From source file:org.gumtree.vis.awt.PlotFactory.java
private static NumberAxis createYAxis(IXYZDataset dataset) { String title = ""; String yTitle = dataset.getYTitle(); if (yTitle != null) { title += yTitle;//from www . jav a 2 s . c om } String yUnits = dataset.getYUnits(); if (yUnits != null) { title += " (" + yUnits + ")"; } if (title.trim().length() == 0) { title = null; } NumberAxis yAxis = new NumberAxis(title); yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); yAxis.setLowerMargin(0.0); yAxis.setUpperMargin(0.0); yAxis.setAutoRangeIncludesZero(false); return yAxis; }
From source file:org.gumtree.vis.awt.PlotFactory.java
private static NumberAxis createXAxis(IXYZDataset dataset) { String title = ""; String xTitle = dataset.getXTitle(); if (xTitle != null) { title += xTitle;/*from w w w .j av a 2 s .c o m*/ } String xUnits = dataset.getXUnits(); if (xUnits != null) { title += " (" + xUnits + ")"; } if (title.trim().length() == 0) { title = null; } NumberAxis xAxis = new NumberAxis(title); xAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); xAxis.setAutoRangeIncludesZero(false); return xAxis; }
From source file:org.hxzon.demo.jfreechart.OtherDatasetDemo.java
private static JFreeChart createStackedXYAreaChart(TableXYDataset dataset) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); xAxis.setLowerMargin(0.0);// w w w . j a v a 2 s .c o m xAxis.setUpperMargin(0.0); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = new StandardXYToolTipGenerator(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(toolTipGenerator, urlGenerator); renderer.setOutline(true); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); plot.setRangeAxis(yAxis); // forces recalculation of the axis range JFreeChart chart = new JFreeChart("StackedXYArea Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); return chart; }
From source file:ec.util.chart.swing.JTimeSeriesRendererSupportDemo.java
private static JFreeChart createTsChart() { XYPlot plot = new XYPlot(); plot.setAxisOffset(RectangleInsets.ZERO_INSETS); DateAxis domainAxis = new DateAxis(); domainAxis.setTickLabelsVisible(false); domainAxis.setLowerMargin(0.02);/*w ww .ja va2s .c o m*/ domainAxis.setUpperMargin(0.02); plot.setDomainAxis(domainAxis); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setTickLabelsVisible(false); rangeAxis.setLowerMargin(0.02); rangeAxis.setUpperMargin(0.02); plot.setRangeAxis(rangeAxis); JFreeChart result = new JFreeChart("", null, plot, true); result.setPadding(new RectangleInsets(5, 5, 5, 5)); result.getLegend().setFrame(BlockBorder.NONE); result.getLegend().setBackgroundPaint(null); return result; }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * DOC xqliu Comment method "createStackedBarChart". * /*w w w . j a v a 2 s. c om*/ * @param title * @param domainAxisLabel * @param rangeAxisLabel * @param dataset * @param orientation * @param legend * @param tooltips * @param urls * @return */ public static JFreeChart createStackedBarChart(String title, String domainAxisLabel, String rangeAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { // ADD msjian TDQ-5112 2012-4-10: after upgrate to jfreechart-1.0.12.jar, change the default chart wallPaint ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); // TDQ-5112~ final JFreeChart chart = ChartFactory.createStackedBarChart(title, domainAxisLabel, rangeAxisLabel, dataset, orientation, legend, tooltips, urls); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRangeGridlinesVisible(true); StackedBarRenderer sbr = (StackedBarRenderer) plot.getRenderer(); sbr.setBaseItemLabelsVisible(true); sbr.setRenderAsPercentages(true); sbr.setBaseItemLabelGenerator(new DQRuleItemLabelGenerator("{3}", NumberFormat.getIntegerInstance())); //$NON-NLS-1$ sbr.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER)); // ADD xqliu 2010-03-10 feature 10834 // sbr.setBaseToolTipGenerator(new DQRuleToolTipGenerator(ChartDecorator.NEW_TOOL_TIP_FORMAT_STRING, // NumberFormat // .getInstance())); // ~10834 // ADD TDQ-5251 msjian 2012-7-31: do not display the shadow sbr.setShadowVisible(false); // TDQ-5251~ NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setNumberFormatOverride(NumberFormat.getPercentInstance()); axis.setUpperMargin(0.05f); axis.setLowerMargin(0.01f); return chart; }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * //w ww . j a v a 2s . c o m * DOC zshen Comment method "createMatchRuleBarChart". * * @param title * @param dataset * @return */ public static JFreeChart createMatchRuleBarChart(String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset) { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart localJFreeChart = ChartFactory.createBarChart(null, categoryAxisLabel, valueAxisLabel, dataset, PlotOrientation.VERTICAL, false, true, false); localJFreeChart.addSubtitle(new TextTitle( Messages.getString("DataChart.title", sumItemCount(dataset), sumGroupCount(dataset)))); //$NON-NLS-1$ CategoryPlot plot = (CategoryPlot) localJFreeChart.getPlot(); // get real color list from ChartDecorator.COLOR_LIST dataset.getColumnKeys() List<Color> currentColorList = null; try { currentColorList = getCurrentColorList(dataset.getColumnKeys()); } catch (NumberFormatException e) { log.warn(e, e); currentColorList = ChartDecorator.COLOR_LIST; } BarRenderer barRenderer = new TalendBarRenderer(true, currentColorList); barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); barRenderer.setBaseItemLabelsVisible(true); // remove the shadow barRenderer.setShadowVisible(Boolean.FALSE); plot.setRenderer(barRenderer); CategoryAxis localCategoryAxis = plot.getDomainAxis(); localCategoryAxis.setCategoryMargin(0.25D); localCategoryAxis.setUpperMargin(0.02D); localCategoryAxis.setLowerMargin(0.02D); NumberAxis localNumberAxis = (NumberAxis) plot.getRangeAxis(); localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); localNumberAxis.setUpperMargin(0.1D); return localJFreeChart; }