List of usage examples for org.jfree.chart.axis CategoryAxis setUpperMargin
public void setUpperMargin(double margin)
From source file:org.jfree.chart.demo.StatisticalLineChartDemo1.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createLineChart("Statistical Line Chart Demo 1", "Type", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setUpperMargin(0.0D); categoryaxis.setLowerMargin(0.0D);/*from www.j a v a 2 s . c o m*/ NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setAutoRangeIncludesZero(true); StatisticalLineAndShapeRenderer statisticallineandshaperenderer = new StatisticalLineAndShapeRenderer(true, false); categoryplot.setRenderer(statisticallineandshaperenderer); return jfreechart; }
From source file:org.jfree.chart.demo.StackedAreaChartDemo1.java
public static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createStackedAreaChart("Stacked Area Chart", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setForegroundAlpha(0.85F); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setLowerMargin(0.0D);// ww w .java 2s. c o m categoryaxis.setUpperMargin(0.0D); categoryaxis.setCategoryMargin(0.0D); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer(); categoryitemrenderer.setBaseItemLabelsVisible(true); return jfreechart; }
From source file:org.jfree.chart.demo.ParetoChartDemo1.java
public static JFreeChart createChart(CategoryDataset acategorydataset[]) { JFreeChart jfreechart = ChartFactory.createBarChart("Freshmeat Software Projects", "Language", "Projects", acategorydataset[0], PlotOrientation.VERTICAL, true, true, false); jfreechart.addSubtitle(new TextTitle("By Programming Language")); jfreechart.addSubtitle(new TextTitle("As at 5 March 2003")); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setLowerMargin(0.02D);/*from w w w . j av a2 s. c o m*/ categoryaxis.setUpperMargin(0.02D); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer(); NumberAxis numberaxis1 = new NumberAxis("Percent"); numberaxis1.setNumberFormatOverride(NumberFormat.getPercentInstance()); categoryplot.setRangeAxis(1, numberaxis1); categoryplot.setDataset(1, acategorydataset[1]); categoryplot.setRenderer(1, lineandshaperenderer); categoryplot.mapDatasetToRangeAxis(1, 1); categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return jfreechart; }
From source file:org.jfree.chart.demo.AreaChartDemo1.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createAreaChart("Area Chart", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); TextTitle texttitle = new TextTitle( "An area chart demonstration. We use this subtitle as an example of what happens when you get a really long title or subtitle."); texttitle.setFont(new Font("SansSerif", 0, 12)); texttitle.setPosition(RectangleEdge.TOP); texttitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.050000000000000003D, 0.050000000000000003D, 0.050000000000000003D, 0.050000000000000003D)); texttitle.setVerticalAlignment(VerticalAlignment.BOTTOM); jfreechart.addSubtitle(texttitle);//from ww w . j a v a 2 s. c o m CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setForegroundAlpha(0.5F); categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setDomainGridlinesVisible(true); categoryplot.setDomainGridlinePaint(Color.white); categoryplot.setRangeGridlinesVisible(true); categoryplot.setRangeGridlinePaint(Color.white); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); categoryaxis.setLowerMargin(0.0D); categoryaxis.setUpperMargin(0.0D); categoryaxis.addCategoryLabelToolTip("Type 1", "The first type."); categoryaxis.addCategoryLabelToolTip("Type 2", "The second type."); categoryaxis.addCategoryLabelToolTip("Type 3", "The third type."); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setLabelAngle(0.0D); return jfreechart; }
From source file:eu.delving.sip.base.ReportChartHelper.java
private static JPanel finishBarChart(JFreeChart chart, Color... colors) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); plot.setRangePannable(true);//from w w w . j a v a 2s .c o m if (colors.length > 0) plot.setRenderer(new CustomRenderer(colors)); BarRenderer bar = (BarRenderer) plot.getRenderer(); bar.setItemLabelAnchorOffset(9D); bar.setBaseItemLabelsVisible(true); bar.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); bar.setMaximumBarWidth(0.05); bar.setItemMargin(0.03D); bar.setBasePositiveItemLabelPosition( new ItemLabelPosition(INSIDE12, CENTER_RIGHT, CENTER_RIGHT, -1.5707963267948966D)); bar.setPositiveItemLabelPositionFallback( new ItemLabelPosition(OUTSIDE12, CENTER_LEFT, CENTER_LEFT, -1.5707963267948966D)); CategoryAxis x = plot.getDomainAxis(); x.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); x.setCategoryMargin(0.25D); x.setUpperMargin(0.02D); x.setLowerMargin(0.02D); NumberAxis y = (NumberAxis) plot.getRangeAxis(); y.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); y.setUpperMargin(0.10000000000000001D); ChartUtilities.applyCurrentTheme(chart); return new ChartPanel(chart); }
From source file:com.thalesgroup.hudson.plugins.sourcemonitor.SourceMonitorChartBuilder.java
public static JFreeChart buildChart(SourceMonitorBuildAction action) { JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, "Number of errors", buildDataset(action), PlotOrientation.VERTICAL, true, false, true); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null);/* w w w . j a va 2 s . co m*/ plot.setForegroundAlpha(0.8f); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); CategoryItemRenderer firstRender = new DefaultCategoryItemRenderer(); SourceMonitorRenderer renderer = new SourceMonitorRenderer(action.getUrlName()); plot.setRenderer(firstRender); return chart; }
From source file:com.mxgraph.examples.swing.chart.BarChartDemo1.java
/** * Creates a sample chart.//from ww w . jav a 2 s.c o m * * @param dataset the dataset. * * @return The chart. */ public static JFreeChart createChart(final 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, false); chart.addSubtitle(new TextTitle("http://www.bupt.edu.cn", new Font("", Font.ITALIC, 10))); // chart.setBackgroundPaint(Color.white); // chart.setBackgroundPaint(Color.getHSBColor(2, 29, 100)); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setBaseItemLabelsVisible(true); // renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setCategoryMargin(0.1);// categoryAxis.setUpperMargin(0.02); categoryAxis.setLowerMargin(0.02); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.10); // 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); chart.getTitle().setFont(new Font("", Font.PLAIN, 16));// CategoryAxis domainAxis = plot.getDomainAxis(); // domainAxis.setLabelFont(new Font("", Font.PLAIN, 14)); // domainAxis.setTickLabelFont(new Font("", Font.PLAIN, 10)); // rangeAxis.setLabelFont(new Font("", Font.PLAIN, 15)); chart.getLegend().setItemFont(new Font("", Font.PLAIN, 15)); return chart; }
From source file:org.jenkinsci.plugins.todos.TodosChartBuilder.java
/** * Build a trend chart from the provided data. * /*from w w w . j a v a2 s .co m*/ * @param action * the build action * @return the trend chart */ public static JFreeChart buildChart(TodosBuildAction action) { String strComments = Messages.Todos_ReportSummary_Comments(); JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, strComments, buildDataset(action), PlotOrientation.VERTICAL, true, false, true); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); TodosAreaRenderer renderer = new TodosAreaRenderer(action.getUrlName()); plot.setRenderer(renderer); return chart; }
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? );/*from www.j a v a 2s .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:eu.delving.stats.ChartHelper.java
private static JFreeChart finishBarChart(JFreeChart chart, Color... colors) { CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); categoryplot.setRangePannable(true); if (colors.length > 0) categoryplot.setRenderer(new CustomRenderer(colors)); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setItemLabelAnchorOffset(9D); barrenderer.setBaseItemLabelsVisible(true); barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); barrenderer.setMaximumBarWidth(0.05); barrenderer.setItemMargin(0.03D);// ww w .jav a 2 s. co m ItemLabelPosition itemlabelposition = new ItemLabelPosition(INSIDE12, CENTER_RIGHT, CENTER_RIGHT, -1.5707963267948966D); barrenderer.setBasePositiveItemLabelPosition(itemlabelposition); ItemLabelPosition itemlabelposition1 = new ItemLabelPosition(OUTSIDE12, CENTER_LEFT, CENTER_LEFT, -1.5707963267948966D); barrenderer.setPositiveItemLabelPositionFallback(itemlabelposition1); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); categoryaxis.setCategoryMargin(0.25D); categoryaxis.setUpperMargin(0.02D); categoryaxis.setLowerMargin(0.02D); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setUpperMargin(0.10000000000000001D); ChartUtilities.applyCurrentTheme(chart); return chart; }