List of usage examples for org.jfree.chart.plot CategoryMarker setLabelOffsetType
public void setLabelOffsetType(LengthAdjustmentType adj)
From source file:org.pau.assetmanager.viewmodel.chart.PrepareChart.java
public static void prepareJFreeBarChart(JFreeChart jfchart, List<PropertyBook> listOfPropertties, CategoryDataset categoryModel) { CategoryPlot categoryPlot = ((CategoryPlot) jfchart.getPlot()); categoryPlot.getRangeAxis().resizeRange(1.2); categoryPlot.setBackgroundPaint(Color.WHITE); categoryPlot.setDomainGridlinePaint(Color.WHITE); categoryPlot.setRangeMinorGridlinePaint(Color.WHITE); categoryPlot.setRangeGridlinePaint(Color.BLACK); BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer(); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(false); for (int i = 0; i < listOfPropertties.size(); i++) { renderer.setSeriesStroke(i, new BasicStroke(1)); }//from w ww .jav a2s . co m for (int i = 0; i < categoryModel.getColumnKeys().size(); i++) { String label = (String) categoryModel.getColumnKey(i); CategoryMarker marker = new CategoryMarker(label); marker.setLabel(""); marker.setPaint(Color.cyan); marker.setOutlinePaint(Color.cyan); marker.setAlpha(0.1f); marker.setLabelAnchor(RectangleAnchor.TOP); marker.setLabelTextAnchor(TextAnchor.TOP_CENTER); marker.setLabelOffsetType(LengthAdjustmentType.CONTRACT); categoryPlot.addDomainMarker(marker, Layer.BACKGROUND); } renderer.setDrawBarOutline(false); renderer.setShadowVisible(false); renderer.setItemMargin(.1); renderer.setBarPainter(new StandardBarPainter()); }
From source file:org.pau.assetmanager.viewmodel.chart.PrepareChart.java
public static void preparePropertiesVsOwnAllPropertiesJFreeChart(JFreeChart jfchart, CategoryDataset categoryModel) { CategoryPlot categoryPlot = ((CategoryPlot) jfchart.getPlot()); categoryPlot.getRangeAxis().resizeRange(1.2); categoryPlot.setBackgroundPaint(Color.WHITE); categoryPlot.setDomainGridlinePaint(Color.WHITE); categoryPlot.setRangeMinorGridlinePaint(Color.WHITE); categoryPlot.setRangeGridlinePaint(Color.BLACK); BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer(); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelFont(new Font("Serif", Font.PLAIN, 10)); renderer.setItemLabelAnchorOffset(15); renderer.setSeriesStroke(0, new BasicStroke(1)); renderer.setSeriesStroke(1, new BasicStroke(1)); renderer.setSeriesStroke(2, new BasicStroke(1)); renderer.setSeriesStroke(3, new BasicStroke(1)); renderer.setSeriesStroke(4, new BasicStroke(1)); renderer.setSeriesStroke(5, new BasicStroke(1)); renderer.setSeriesPaint(0, new Color(0x77, 0x77, 0xFF)); renderer.setSeriesPaint(1, new Color(0xCC, 0xCC, 0xFF)); renderer.setSeriesPaint(2, new Color(0x00, 0x00, 0xFF)); renderer.setSeriesPaint(3, new Color(0xFF, 0x77, 0x77)); renderer.setSeriesPaint(4, new Color(0xFF, 0xCC, 0xCC)); renderer.setSeriesPaint(5, new Color(0xFF, 0x00, 0x00)); for (int i = 0; i < categoryModel.getColumnKeys().size(); i++) { String label = (String) categoryModel.getColumnKey(i); CategoryMarker marker = new CategoryMarker(label); marker.setLabel(""); marker.setPaint(Color.cyan); marker.setOutlinePaint(Color.cyan); marker.setAlpha(0.1f);/*from w w w. j av a 2 s .co m*/ marker.setLabelAnchor(RectangleAnchor.TOP); marker.setLabelTextAnchor(TextAnchor.TOP_CENTER); marker.setLabelOffsetType(LengthAdjustmentType.CONTRACT); categoryPlot.addDomainMarker(marker, Layer.BACKGROUND); } renderer.setDrawBarOutline(false); renderer.setShadowVisible(false); renderer.setItemMargin(.1); renderer.setBarPainter(new StandardBarPainter()); renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.TOP_RIGHT)); renderer.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.BOTTOM_RIGHT)); }
From source file:edu.ucla.stat.SOCR.chart.demo.BarChartDemo3.java
/** * Creates a sample chart./*from ww w . j ava 2s . com*/ * * @param dataset the dataset. * * @return a sample chart. */ protected JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation !legendPanelOn, // include legend true, false); chart.setBackgroundPaint(Color.lightGray); // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA!"); CategoryItemRenderer renderer = new CustomBarRenderer(new Paint[] { Color.red, Color.blue, Color.green, Color.yellow, Color.orange, Color.cyan, Color.magenta, Color.blue }); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(true); ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0); renderer.setBasePositiveItemLabelPosition(p); plot.setRenderer(renderer); CategoryMarker marker = new CategoryMarker("Category 3"); marker.setLabel("Special"); marker.setPaint(new Color(0xDD, 0xFF, 0xDD, 0x80)); marker.setAlpha(0.5f); marker.setLabelAnchor(RectangleAnchor.TOP_LEFT); marker.setLabelTextAnchor(TextAnchor.TOP_LEFT); marker.setLabelOffsetType(LengthAdjustmentType.CONTRACT); plot.addDomainMarker(marker, Layer.BACKGROUND); // change the margin at the top of the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerMargin(0.15); rangeAxis.setUpperMargin(0.15); BarRenderer seriesRenderer = (BarRenderer) plot.getRenderer(); seriesRenderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); setCategorySummary(dataset); return chart; }
From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java
public void addDomainMarker(CategoryPlot plot, cfCHARTDOMAINMARKERData dmData) throws cfmRunTimeException { CategoryMarker domainMarker = new CategoryMarker(dmData.getValue()); boolean drawAsLine = false; if (dmData.getShape().equals("line")) drawAsLine = true;/*from www . jav a2s.c o m*/ domainMarker.setDrawAsLine(drawAsLine); domainMarker.setPaint(convertStringToColor(dmData.getColor())); if (dmData.getLabel() != null) { domainMarker.setLabel(dmData.getLabel()); domainMarker.setLabelPaint(convertStringToColor(dmData.getLabelColor())); String labelPos = dmData.getLabelPosition(); if (labelPos.equals("top_left")) { domainMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT); if (drawAsLine) domainMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); else domainMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT); } else if (labelPos.equals("top")) { domainMarker.setLabelAnchor(RectangleAnchor.TOP); domainMarker.setLabelTextAnchor(TextAnchor.TOP_CENTER); } else if (labelPos.equals("top_right")) { domainMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); if (drawAsLine) domainMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT); else domainMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); } else if (labelPos.equals("left")) { domainMarker.setLabelAnchor(RectangleAnchor.LEFT); if (drawAsLine) domainMarker.setLabelTextAnchor(TextAnchor.CENTER_RIGHT); else domainMarker.setLabelTextAnchor(TextAnchor.CENTER_LEFT); } else if (labelPos.equals("center")) { domainMarker.setLabelAnchor(RectangleAnchor.CENTER); domainMarker.setLabelTextAnchor(TextAnchor.CENTER); } else if (labelPos.equals("right")) { domainMarker.setLabelAnchor(RectangleAnchor.RIGHT); if (drawAsLine) domainMarker.setLabelTextAnchor(TextAnchor.CENTER_LEFT); else domainMarker.setLabelTextAnchor(TextAnchor.CENTER_RIGHT); } else if (labelPos.equals("bottom_left")) { domainMarker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); if (drawAsLine) domainMarker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); else domainMarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT); } else if (labelPos.equals("bottom")) { domainMarker.setLabelAnchor(RectangleAnchor.BOTTOM); domainMarker.setLabelTextAnchor(TextAnchor.BOTTOM_CENTER); } else if (labelPos.equals("bottom_right")) { domainMarker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); if (drawAsLine) domainMarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT); else domainMarker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); } domainMarker.setLabelOffsetType(LengthAdjustmentType.NO_CHANGE); domainMarker.setLabelFont( getFont(dmData.getFont(), dmData.getFontBold(), dmData.getFontItalic(), dmData.getFontSize())); } plot.addDomainMarker(domainMarker, Layer.BACKGROUND); }