Java Code Examples for org.jfree.chart.axis.CategoryAxis#setUpperMargin()
The following examples show how to use
org.jfree.chart.axis.CategoryAxis#setUpperMargin() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpressionProfile.java From chipster with MIT License | 6 votes |
public JFreeChart createProfileChart(CategoryDataset categoryDataset, List<ProfileRow> rows, String name) throws MicroarrayException { // draw plot CategoryAxis categoryAxis = new CategoryAxis("sample"); categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); categoryAxis.setUpperMargin(0.0); categoryAxis.setLowerMargin(0.0); ValueAxis valueAxis = new NumberAxis("expression"); plot = new CategoryPlot(categoryDataset, categoryAxis, valueAxis, createRenderer(rows)); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart("Expression profile for " + name, JFreeChart.DEFAULT_TITLE_FONT, plot, false); return chart; }
Example 2
Source File: StatisticChart.java From BART with MIT License | 5 votes |
public static JPanel createStatisticBarChart(String title,String categoryX,String valueY,CategoryDataset dataset) { final CategoryAxis xAxis = new CategoryAxis(categoryX); xAxis.setLowerMargin(0.01d); // percentage of space before first bar xAxis.setUpperMargin(0.01d); // percentage of space after last bar xAxis.setCategoryMargin(0.05d); // percentage of space between categories final ValueAxis yAxis = new NumberAxis("Value"); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, new StatisticalBarRenderer()); JFreeChart statChart = new JFreeChart(title, new Font("Helvetica", Font.BOLD, 14), plot, true); ChartPanel panel = new ChartPanel(statChart); panel.setPreferredSize(new Dimension(700, 440)); return panel; }
Example 3
Source File: ServerWideReportManagerImpl.java From sakai with Educational Community License v2.0 | 5 votes |
private byte[] generateBoxAndWhiskerChart (BoxAndWhiskerCategoryDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createBoxAndWhiskerChart (null, null, null, dataset, false); // set background chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ())); // set chart border chart.setPadding (new RectangleInsets (10, 5, 5, 5)); chart.setBorderVisible (true); chart.setBorderPaint (parseColor ("#cccccc")); // set anti alias chart.setAntiAlias (true); CategoryPlot plot = (CategoryPlot) chart.getPlot (); plot.setDomainGridlinePaint (Color.white); plot.setDomainGridlinesVisible (true); plot.setRangeGridlinePaint (Color.white); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis (); rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ()); CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis (); domainAxis.setLowerMargin (0.0); domainAxis.setUpperMargin (0.0); BufferedImage img = chart.createBufferedImage (width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try{ ImageIO.write(img, "png", out); }catch(IOException e){ log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
Example 4
Source File: AWSDeviceFarmGraph.java From aws-device-farm-jenkins-plugin with Apache License 2.0 | 5 votes |
/** * Create graph based on the given dataset and constraints. * * @return The JFreeChart graph. */ protected JFreeChart createGraph() { // Create chart. JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.WHITE); // Create chart legend. LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); // Create chart plot. CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setForegroundAlpha(0.7f); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.darkGray); // Create domain (x) axis. CategoryAxis domain = new ShiftedCategoryAxis(xLabel); domain.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domain.setLowerMargin(0.0); domain.setUpperMargin(0.0); domain.setCategoryMargin(0.0); plot.setDomainAxis(domain); // Create range (y) axis. NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setAutoRange(true); range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Create renderer and paint the chart. CategoryItemRenderer renderer = plot.getRenderer(); plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0)); // Set chart colors for sections. for (int i = 0; i < colors.length; i++) { renderer.setSeriesPaint(i, colors[i]); } return chart; }
Example 5
Source File: ServerWideReportManagerImpl.java From sakai with Educational Community License v2.0 | 5 votes |
private byte[] generateBoxAndWhiskerChart (BoxAndWhiskerCategoryDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createBoxAndWhiskerChart (null, null, null, dataset, false); // set background chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ())); // set chart border chart.setPadding (new RectangleInsets (10, 5, 5, 5)); chart.setBorderVisible (true); chart.setBorderPaint (parseColor ("#cccccc")); // set anti alias chart.setAntiAlias (true); CategoryPlot plot = (CategoryPlot) chart.getPlot (); plot.setDomainGridlinePaint (Color.white); plot.setDomainGridlinesVisible (true); plot.setRangeGridlinePaint (Color.white); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis (); rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ()); CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis (); domainAxis.setLowerMargin (0.0); domainAxis.setUpperMargin (0.0); BufferedImage img = chart.createBufferedImage (width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try{ ImageIO.write(img, "png", out); }catch(IOException e){ log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
Example 6
Source File: CumulativeCurveChart.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
public JFreeChart createChart(DatasetMap datasetMap) { CategoryDataset datasetValue=(CategoryDataset)datasetMap.getDatasets().get("1"); CategoryDataset datasetCumulative=(CategoryDataset)datasetMap.getDatasets().get("2"); JFreeChart chart = ChartFactory.createBarChart( name, // chart title xLabel, // domain axis label yLabel, // range axis label datasetValue, // data PlotOrientation.VERTICAL, true, // include legend true, false ); chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); NumberAxis axis2 = new NumberAxis("Percent"); axis2.setNumberFormatOverride(NumberFormat.getPercentInstance()); plot.setRangeAxis(1, axis2); plot.setDataset(1, datasetCumulative); plot.setRenderer(1, renderer2); plot.mapDatasetToRangeAxis(1, 1); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return chart; }
Example 7
Source File: ParetoChartPlotter.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
private JFreeChart createChart() { if (data.getItemCount() > 0) { // get cumulative percentages KeyedValues cumulative = DataUtilities.getCumulativePercentages(data); CategoryDataset categoryDataset = DatasetUtilities.createCategoryDataset( "Count for " + this.dataTable.getColumnName(this.countColumn) + " = " + countValue, data); // create the chart... final JFreeChart chart = ChartFactory.createBarChart(null, // chart title this.dataTable.getColumnName(this.groupByColumn), // domain axis label "Count", // range axis label categoryDataset, // data PlotOrientation.VERTICAL, true, // include legend true, false); // set the background color for the chart... chart.setBackgroundPaint(Color.WHITE); // get a reference to the plot for further customization... CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); domainAxis.setLabelFont(LABEL_FONT_BOLD); domainAxis.setTickLabelFont(LABEL_FONT); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US)); rangeAxis.setLabelFont(LABEL_FONT_BOLD); rangeAxis.setTickLabelFont(LABEL_FONT); // second data set (cumulative percentages) CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative (Percent)", cumulative); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setSeriesPaint(0, SwingTools.VERY_DARK_BLUE.darker()); NumberAxis axis2 = new NumberAxis("Percent of " + countValue); axis2.setNumberFormatOverride(NumberFormat.getPercentInstance()); axis2.setLabelFont(LABEL_FONT_BOLD); axis2.setTickLabelFont(LABEL_FONT); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.mapDatasetToRangeAxis(1, 1); axis2.setTickUnit(new NumberTickUnit(0.1)); // show grid lines plot.setRangeGridlinesVisible(true); // bring cumulative line to front plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); if (isLabelRotating()) { domainAxis.setTickLabelsVisible(true); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d)); } return chart; } else { return null; } }
Example 8
Source File: ServerWideReportManagerImpl.java From sakai with Educational Community License v2.0 | 4 votes |
private byte[] generateStackedAreaChart (CategoryDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createStackedAreaChart (null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls ); // set background chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ())); // set chart border chart.setPadding (new RectangleInsets (10, 5, 5, 5)); chart.setBorderVisible (true); chart.setBorderPaint (parseColor ("#cccccc")); // set anti alias chart.setAntiAlias (true); CategoryPlot plot = (CategoryPlot) chart.getPlot (); // set transparency plot.setForegroundAlpha (0.7f); plot.setAxisOffset (new RectangleInsets (5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint (Color.lightGray); plot.setDomainGridlinesVisible (true); plot.setDomainGridlinePaint (Color.white); plot.setRangeGridlinesVisible (true); plot.setRangeGridlinePaint (Color.white); // set colour of regular users using Karate belt colour: white, green, blue, brown, black/gold CategoryItemRenderer renderer = plot.getRenderer (); renderer.setSeriesPaint (0, new Color (205, 173, 0)); // gold users renderer.setSeriesPaint (1, new Color (139, 69, 19)); renderer.setSeriesPaint (2, Color.BLUE); renderer.setSeriesPaint (3, Color.GREEN); renderer.setSeriesPaint (4, Color.WHITE); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis (); rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ()); CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis (); domainAxis.setCategoryLabelPositions (CategoryLabelPositions.DOWN_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); BufferedImage img = chart.createBufferedImage (width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try{ ImageIO.write(img, "png", out); }catch(IOException e){ log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
Example 9
Source File: ServerWideReportManagerImpl.java From sakai with Educational Community License v2.0 | 4 votes |
private byte[] generateLayeredBarChart (CategoryDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createBarChart (null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls ); // set background chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ())); // set chart border chart.setPadding (new RectangleInsets (10, 5, 5, 5)); chart.setBorderVisible (true); chart.setBorderPaint (parseColor ("#cccccc")); // set anti alias chart.setAntiAlias (true); CategoryPlot plot = (CategoryPlot) chart.getPlot (); // disable bar outlines... LayeredBarRenderer renderer = new LayeredBarRenderer (); renderer.setDrawBarOutline (false); renderer.setSeriesBarWidth (0, .6); renderer.setSeriesBarWidth (1, .8); renderer.setSeriesBarWidth (2, 1.0); plot.setRenderer (renderer); // for this renderer, we need to draw the first series last... plot.setRowRenderingOrder (SortOrder.DESCENDING); // 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); CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis (); domainAxis.setCategoryLabelPositions (CategoryLabelPositions.DOWN_45); domainAxis.setLowerMargin (0.0); domainAxis.setUpperMargin (0.0); BufferedImage img = chart.createBufferedImage (width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try{ ImageIO.write(img, "png", out); }catch(IOException e){ log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
Example 10
Source File: ServerWideReportManagerImpl.java From sakai with Educational Community License v2.0 | 4 votes |
private byte[] createToolAnalysisChart (int width, int height) { CategoryDataset dataset = getToolAnalysisDataSet (); if (dataset == null) { return generateNoDataChart(width, height); } JFreeChart chart = ChartFactory.createBarChart ( null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // the plot orientation false, // legend false, // tooltips false // urls ); // set background chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ())); // set chart border chart.setPadding (new RectangleInsets (10, 5, 5, 5)); chart.setBorderVisible (true); chart.setBorderPaint (parseColor ("#cccccc")); // set anti alias chart.setAntiAlias (true); CategoryPlot plot = (CategoryPlot) chart.getPlot (); // set transparency plot.setForegroundAlpha (0.7f); plot.setAxisOffset (new RectangleInsets (5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint (Color.lightGray); plot.setDomainGridlinesVisible (false); plot.setRangeGridlinesVisible (true); plot.setRangeGridlinePaint (Color.white); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); domainAxis.setUpperMargin (0); domainAxis.setLowerMargin (0); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setUpperMargin(0.20); rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ()); BarRenderer renderer = (BarRenderer) plot.getRenderer(); CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{1}", NumberFormat.getInstance(new ResourceLoader().getLocale())); renderer.setDefaultItemLabelGenerator(generator); renderer.setDefaultItemLabelFont(new Font("SansSerif", Font.PLAIN, 9)); renderer.setDefaultItemLabelsVisible(true); renderer.setItemMargin (0); renderer.setSeriesPaint (0, Color.BLUE); BufferedImage img = chart.createBufferedImage (width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try{ ImageIO.write(img, "png", out); }catch(IOException e){ log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
Example 11
Source File: CategoryAxisTests.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { CategoryAxis a1 = new CategoryAxis("Test"); CategoryAxis a2 = new CategoryAxis("Test"); assertTrue(a1.equals(a2)); // lowerMargin a1.setLowerMargin(0.15); assertFalse(a1.equals(a2)); a2.setLowerMargin(0.15); assertTrue(a1.equals(a2)); // upperMargin a1.setUpperMargin(0.15); assertFalse(a1.equals(a2)); a2.setUpperMargin(0.15); assertTrue(a1.equals(a2)); // categoryMargin a1.setCategoryMargin(0.15); assertFalse(a1.equals(a2)); a2.setCategoryMargin(0.15); assertTrue(a1.equals(a2)); // maxCategoryLabelWidthRatio a1.setMaximumCategoryLabelWidthRatio(0.98f); assertFalse(a1.equals(a2)); a2.setMaximumCategoryLabelWidthRatio(0.98f); assertTrue(a1.equals(a2)); // categoryLabelPositionOffset a1.setCategoryLabelPositionOffset(11); assertFalse(a1.equals(a2)); a2.setCategoryLabelPositionOffset(11); assertTrue(a1.equals(a2)); // categoryLabelPositions a1.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); assertFalse(a1.equals(a2)); a2.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); assertTrue(a1.equals(a2)); // categoryLabelToolTips a1.addCategoryLabelToolTip("Test", "Check"); assertFalse(a1.equals(a2)); a2.addCategoryLabelToolTip("Test", "Check"); assertTrue(a1.equals(a2)); // tickLabelFont a1.setTickLabelFont("C1", new Font("Dialog", Font.PLAIN, 21)); assertFalse(a1.equals(a2)); a2.setTickLabelFont("C1", new Font("Dialog", Font.PLAIN, 21)); assertTrue(a1.equals(a2)); // tickLabelPaint a1.setTickLabelPaint("C1", Color.red); assertFalse(a1.equals(a2)); a2.setTickLabelPaint("C1", Color.red); assertTrue(a1.equals(a2)); // tickLabelPaint2 a1.setTickLabelPaint("C1", new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertFalse(a1.equals(a2)); a2.setTickLabelPaint("C1", new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertTrue(a1.equals(a2)); }
Example 12
Source File: CategoryAxisTests.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { CategoryAxis a1 = new CategoryAxis("Test"); CategoryAxis a2 = new CategoryAxis("Test"); assertTrue(a1.equals(a2)); // lowerMargin a1.setLowerMargin(0.15); assertFalse(a1.equals(a2)); a2.setLowerMargin(0.15); assertTrue(a1.equals(a2)); // upperMargin a1.setUpperMargin(0.15); assertFalse(a1.equals(a2)); a2.setUpperMargin(0.15); assertTrue(a1.equals(a2)); // categoryMargin a1.setCategoryMargin(0.15); assertFalse(a1.equals(a2)); a2.setCategoryMargin(0.15); assertTrue(a1.equals(a2)); // maxCategoryLabelWidthRatio a1.setMaximumCategoryLabelWidthRatio(0.98f); assertFalse(a1.equals(a2)); a2.setMaximumCategoryLabelWidthRatio(0.98f); assertTrue(a1.equals(a2)); // categoryLabelPositionOffset a1.setCategoryLabelPositionOffset(11); assertFalse(a1.equals(a2)); a2.setCategoryLabelPositionOffset(11); assertTrue(a1.equals(a2)); // categoryLabelPositions a1.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); assertFalse(a1.equals(a2)); a2.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); assertTrue(a1.equals(a2)); // categoryLabelToolTips a1.addCategoryLabelToolTip("Test", "Check"); assertFalse(a1.equals(a2)); a2.addCategoryLabelToolTip("Test", "Check"); assertTrue(a1.equals(a2)); // tickLabelFont a1.setTickLabelFont("C1", new Font("Dialog", Font.PLAIN, 21)); assertFalse(a1.equals(a2)); a2.setTickLabelFont("C1", new Font("Dialog", Font.PLAIN, 21)); assertTrue(a1.equals(a2)); // tickLabelPaint a1.setTickLabelPaint("C1", Color.red); assertFalse(a1.equals(a2)); a2.setTickLabelPaint("C1", Color.red); assertTrue(a1.equals(a2)); // tickLabelPaint2 a1.setTickLabelPaint("C1", new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertFalse(a1.equals(a2)); a2.setTickLabelPaint("C1", new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertTrue(a1.equals(a2)); }
Example 13
Source File: ServerWideReportManagerImpl.java From sakai with Educational Community License v2.0 | 4 votes |
private byte[] generateStackedAreaChart (CategoryDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createStackedAreaChart (null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls ); // set background chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ())); // set chart border chart.setPadding (new RectangleInsets (10, 5, 5, 5)); chart.setBorderVisible (true); chart.setBorderPaint (parseColor ("#cccccc")); // set anti alias chart.setAntiAlias (true); CategoryPlot plot = (CategoryPlot) chart.getPlot (); // set transparency plot.setForegroundAlpha (0.7f); plot.setAxisOffset (new RectangleInsets (5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint (Color.lightGray); plot.setDomainGridlinesVisible (true); plot.setDomainGridlinePaint (Color.white); plot.setRangeGridlinesVisible (true); plot.setRangeGridlinePaint (Color.white); // set colour of regular users using Karate belt colour: white, green, blue, brown, black/gold CategoryItemRenderer renderer = plot.getRenderer (); renderer.setSeriesPaint (0, new Color (205, 173, 0)); // gold users renderer.setSeriesPaint (1, new Color (139, 69, 19)); renderer.setSeriesPaint (2, Color.BLUE); renderer.setSeriesPaint (3, Color.GREEN); renderer.setSeriesPaint (4, Color.WHITE); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis (); rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ()); CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis (); domainAxis.setCategoryLabelPositions (CategoryLabelPositions.DOWN_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); BufferedImage img = chart.createBufferedImage (width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try{ ImageIO.write(img, "png", out); }catch(IOException e){ log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
Example 14
Source File: ServerWideReportManagerImpl.java From sakai with Educational Community License v2.0 | 4 votes |
private byte[] generateLayeredBarChart (CategoryDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createBarChart (null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls ); // set background chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ())); // set chart border chart.setPadding (new RectangleInsets (10, 5, 5, 5)); chart.setBorderVisible (true); chart.setBorderPaint (parseColor ("#cccccc")); // set anti alias chart.setAntiAlias (true); CategoryPlot plot = (CategoryPlot) chart.getPlot (); // disable bar outlines... LayeredBarRenderer renderer = new LayeredBarRenderer (); renderer.setDrawBarOutline (false); renderer.setSeriesBarWidth (0, .6); renderer.setSeriesBarWidth (1, .8); renderer.setSeriesBarWidth (2, 1.0); plot.setRenderer (renderer); // for this renderer, we need to draw the first series last... plot.setRowRenderingOrder (SortOrder.DESCENDING); // 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); CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis (); domainAxis.setCategoryLabelPositions (CategoryLabelPositions.DOWN_45); domainAxis.setLowerMargin (0.0); domainAxis.setUpperMargin (0.0); BufferedImage img = chart.createBufferedImage (width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try{ ImageIO.write(img, "png", out); }catch(IOException e){ log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
Example 15
Source File: ServerWideReportManagerImpl.java From sakai with Educational Community License v2.0 | 4 votes |
private byte[] createToolAnalysisChart (int width, int height) { CategoryDataset dataset = getToolAnalysisDataSet (); if (dataset == null) { return generateNoDataChart(width, height); } JFreeChart chart = ChartFactory.createBarChart ( null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // the plot orientation false, // legend false, // tooltips false // urls ); // set background chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ())); // set chart border chart.setPadding (new RectangleInsets (10, 5, 5, 5)); chart.setBorderVisible (true); chart.setBorderPaint (parseColor ("#cccccc")); // set anti alias chart.setAntiAlias (true); CategoryPlot plot = (CategoryPlot) chart.getPlot (); // set transparency plot.setForegroundAlpha (0.7f); plot.setAxisOffset (new RectangleInsets (5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint (Color.lightGray); plot.setDomainGridlinesVisible (false); plot.setRangeGridlinesVisible (true); plot.setRangeGridlinePaint (Color.white); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); domainAxis.setUpperMargin (0); domainAxis.setLowerMargin (0); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setUpperMargin(0.20); rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ()); BarRenderer renderer = (BarRenderer) plot.getRenderer(); CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{1}", NumberFormat.getInstance(new ResourceLoader().getLocale())); renderer.setDefaultItemLabelGenerator(generator); renderer.setDefaultItemLabelFont(new Font("SansSerif", Font.PLAIN, 9)); renderer.setDefaultItemLabelsVisible(true); renderer.setItemMargin (0); renderer.setSeriesPaint (0, Color.BLUE); BufferedImage img = chart.createBufferedImage (width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try{ ImageIO.write(img, "png", out); }catch(IOException e){ log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }