List of usage examples for org.jfree.chart.annotations CategoryTextAnnotation setCategoryAnchor
public void setCategoryAnchor(CategoryAnchor anchor)
From source file:org.jfree.chart.demo.BarChart3DDemo4.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createBarChart3D("Student Grades", "Students", "Grade", categorydataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); CustomBarRenderer3D custombarrenderer3d = new CustomBarRenderer3D(); custombarrenderer3d.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); custombarrenderer3d.setBaseItemLabelsVisible(true); custombarrenderer3d.setItemLabelAnchorOffset(10D); custombarrenderer3d.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); categoryplot.setRenderer(custombarrenderer3d); ValueMarker valuemarker = new ValueMarker(0.69999999999999996D, new Color(200, 200, 255), new BasicStroke(1.0F), new Color(200, 200, 255), new BasicStroke(1.0F), 1.0F); categoryplot.addRangeMarker(valuemarker, Layer.BACKGROUND); custombarrenderer3d.setBaseItemLabelsVisible(true); custombarrenderer3d.setMaximumBarWidth(0.050000000000000003D); CategoryTextAnnotation categorytextannotation = new CategoryTextAnnotation("Minimum grade to pass", "Robert", 0.70999999999999996D); categorytextannotation.setCategoryAnchor(CategoryAnchor.START); categorytextannotation.setFont(new Font("SansSerif", 0, 12)); categorytextannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); categoryplot.addAnnotation(categorytextannotation); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); numberaxis.setUpperMargin(0.10000000000000001D); return jfreechart; }
From source file:org.jfree.chart.demo.SurveyResultsDemo1.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createBarChart(null, null, null, categorydataset, PlotOrientation.HORIZONTAL, false, true, false); jfreechart.setBackgroundPaint(Color.white); TextTitle texttitle = new TextTitle( "Figure 7 | I. Resources - The site offers users relevant, informative and educational resources"); texttitle.setHorizontalAlignment(HorizontalAlignment.LEFT); texttitle.setBackgroundPaint(Color.red); texttitle.setPaint(Color.white); jfreechart.setTitle(texttitle);//w ww .ja v a2s . co m CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setOutlinePaint(null); categoryplot.setDomainGridlinesVisible(true); categoryplot.setDomainGridlinePosition(CategoryAnchor.END); categoryplot.setDomainGridlineStroke(new BasicStroke(0.5F)); categoryplot.setDomainGridlinePaint(Color.black); categoryplot.setRangeGridlinesVisible(false); categoryplot.clearRangeMarkers(); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setVisible(false); categoryaxis.setCategoryMargin(0.5D); categoryplot.getRangeAxis().setVisible(false); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setSeriesPaint(0, new Color(156, 164, 74)); barrenderer.setDrawBarOutline(false); barrenderer.setBaseItemLabelsVisible(true); barrenderer.setBaseItemLabelFont(new Font("SansSerif", 1, 10)); ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); barrenderer.setBasePositiveItemLabelPosition(itemlabelposition); CategoryTextAnnotation categorytextannotation = new CategoryTextAnnotation("1. White papers are available.", "Category 1", 0.0D); categorytextannotation.setFont(new Font("SansSerif", 1, 12)); categorytextannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation); CategoryTextAnnotation categorytextannotation1 = new CategoryTextAnnotation( "2. White papers enhance users understanding of the firm and its expertise.", "Category 2", 0.0D); categorytextannotation1.setFont(new Font("SansSerif", 0, 12)); categorytextannotation1.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation1.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation1); CategoryTextAnnotation categorytextannotation2 = new CategoryTextAnnotation( "3. White papers are relevant to the firm's prospects and clients.", "Category 3", 0.0D); categorytextannotation2.setFont(new Font("SansSerif", 0, 12)); categorytextannotation2.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation2.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation2); CategoryTextAnnotation categorytextannotation3 = new CategoryTextAnnotation( "4. White papers are relevant to the firm's positioning.", "Category 4", 0.0D); categorytextannotation3.setFont(new Font("SansSerif", 0, 12)); categorytextannotation3.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation3.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation3); CategoryTextAnnotation categorytextannotation4 = new CategoryTextAnnotation( "5. Case studies are available.", "Category 5", 0.0D); categorytextannotation4.setFont(new Font("SansSerif", 1, 12)); categorytextannotation4.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation4.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation4); CategoryTextAnnotation categorytextannotation5 = new CategoryTextAnnotation( "6. Case studies enhance users understanding of the firm and its expertise.", "Category 6", 0.0D); categorytextannotation5.setFont(new Font("SansSerif", 0, 12)); categorytextannotation5.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation5.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation5); CategoryTextAnnotation categorytextannotation6 = new CategoryTextAnnotation( "7. Case studies are relevant to the firm's prospects and clients.", "Category 7", 0.0D); categorytextannotation6.setFont(new Font("SansSerif", 0, 12)); categorytextannotation6.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation6.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation6); CategoryTextAnnotation categorytextannotation7 = new CategoryTextAnnotation( "8. White papers are relevant to the firm's positioning.", "Category 8", 0.0D); categorytextannotation7.setFont(new Font("SansSerif", 0, 12)); categorytextannotation7.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation7.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation7); CategoryTextAnnotation categorytextannotation8 = new CategoryTextAnnotation( "9. Case studies are available.", "Category 9", 0.0D); categorytextannotation8.setFont(new Font("SansSerif", 1, 12)); categorytextannotation8.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation8.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation8); CategoryTextAnnotation categorytextannotation9 = new CategoryTextAnnotation( "10. Case studies enhance users understanding of the firm and its expertise.", "Category 10", 0.0D); categorytextannotation9.setFont(new Font("SansSerif", 0, 12)); categorytextannotation9.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation9.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation9); CategoryTextAnnotation categorytextannotation10 = new CategoryTextAnnotation( "11. Case studies are relevant to the firm's prospects and clients.", "Category 11", 0.0D); categorytextannotation10.setFont(new Font("SansSerif", 0, 12)); categorytextannotation10.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation10.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation10); CategoryTextAnnotation categorytextannotation11 = new CategoryTextAnnotation( "12. White papers are relevant to the firm's positioning.", "Category 12", 0.0D); categorytextannotation11.setFont(new Font("SansSerif", 0, 12)); categorytextannotation11.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation11.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation11); CategoryTextAnnotation categorytextannotation12 = new CategoryTextAnnotation( "13. Users can easily access resources based on viewer interest.", "Category 13", 0.0D); categorytextannotation12.setFont(new Font("SansSerif", 1, 12)); categorytextannotation12.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation12.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation12); CategoryTextAnnotation categorytextannotation13 = new CategoryTextAnnotation( "14. Access to additional hyperlinks enhances users's ability to find relevant information.", "Category 14", 0.0D); categorytextannotation13.setFont(new Font("SansSerif", 1, 12)); categorytextannotation13.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation13.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation13); CategoryTextAnnotation categorytextannotation14 = new CategoryTextAnnotation("15. OVERALL EFFECTIVENESS.", "Overall", 0.0D); categorytextannotation14.setFont(new Font("SansSerif", 1, 12)); categorytextannotation14.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation14.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation14); return jfreechart; }
From source file:com.intel.stl.ui.common.view.ComponentFactory.java
@SuppressWarnings("unchecked") public static JFreeChart createTopNBarChart2(String yAxisLabel, CategoryDataset dataset) { JFreeChart jfreechart = ChartFactory.createBarChart(null, null, yAxisLabel, dataset, PlotOrientation.HORIZONTAL, false, true, false); CategoryPlot categoryplot = jfreechart.getCategoryPlot(); categoryplot.setBackgroundPaint(null); categoryplot.setOutlinePaint(null);/*from ww w . j a v a 2 s. c o m*/ categoryplot.setDomainGridlinesVisible(true); categoryplot.setDomainGridlinePosition(CategoryAnchor.END); categoryplot.setDomainGridlineStroke(new BasicStroke(0.5F)); categoryplot.setDomainGridlinePaint(UIConstants.INTEL_BORDER_GRAY); categoryplot.setRangeGridlinesVisible(false); categoryplot.clearRangeMarkers(); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setVisible(false); categoryaxis.setCategoryMargin(0.75D); NumberAxis axis = (NumberAxis) categoryplot.getRangeAxis(); axis.setRangeType(RangeType.POSITIVE); axis.setVisible(false); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setShadowVisible(false); barrenderer.setSeriesPaint(0, UIConstants.INTEL_BLUE); barrenderer.setDrawBarOutline(false); barrenderer.setBaseItemLabelsVisible(true); barrenderer.setBaseItemLabelFont(UIConstants.H5_FONT); barrenderer.setBarPainter(new StandardBarPainter()); List<String> names = dataset.getColumnKeys(); for (String name : names) { CategoryTextAnnotation categorytextannotation = new CategoryTextAnnotation(name, name, 0.0D); categorytextannotation.setFont(UIConstants.H6_FONT); categorytextannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation.setCategoryAnchor(CategoryAnchor.MIDDLE); categoryplot.addAnnotation(categorytextannotation); } return jfreechart; }
From source file:org.jfree.chart.demo.SurveyResultsDemo.java
/** * Creates a chart./*from ww w. ja v a2 s .c om*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation false, // include legend true, false); chart.setBackgroundPaint(Color.white); final TextTitle title = new TextTitle("Figure 7 | I. Resources - The site offers users relevant, " + "informative and educational resources"); title.setHorizontalAlignment(HorizontalAlignment.LEFT); title.setBackgroundPaint(Color.red); title.setPaint(Color.white); chart.setTitle(title); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setOutlinePaint(null); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePosition(CategoryAnchor.END); plot.setDomainGridlineStroke(new BasicStroke(0.5f)); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinesVisible(false); plot.clearRangeMarkers(); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); domainAxis.setCategoryMargin(0.50); plot.getRangeAxis().setVisible(false); final CategoryItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, new Color(0x9C, 0xA4, 0x4A)); renderer.setOutlineStroke(null); renderer.setBaseOutlineStroke(null); renderer.setItemLabelsVisible(true); renderer.setItemLabelFont(new Font("SansSerif", Font.BOLD, 10)); final ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setPositiveItemLabelPosition(position); final CategoryTextAnnotation a1 = new CategoryTextAnnotation("1. White papers are available.", "Category 1", 0.0); a1.setFont(new Font("SansSerif", Font.BOLD, 12)); a1.setTextAnchor(TextAnchor.BOTTOM_LEFT); a1.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a1); final CategoryTextAnnotation a2 = new CategoryTextAnnotation( "2. White papers enhance users " + "understanding of the firm and its expertise.", "Category 2", 0.0); a2.setFont(new Font("SansSerif", Font.PLAIN, 12)); a2.setTextAnchor(TextAnchor.BOTTOM_LEFT); a2.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a2); final CategoryTextAnnotation a3 = new CategoryTextAnnotation( "3. White papers are relevant to " + "the firm's prospects and clients.", "Category 3", 0.0); a3.setFont(new Font("SansSerif", Font.PLAIN, 12)); a3.setTextAnchor(TextAnchor.BOTTOM_LEFT); a3.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a3); final CategoryTextAnnotation a4 = new CategoryTextAnnotation( "4. White papers are relevant to " + "the firm's positioning.", "Category 4", 0.0); a4.setFont(new Font("SansSerif", Font.PLAIN, 12)); a4.setTextAnchor(TextAnchor.BOTTOM_LEFT); a4.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a4); final CategoryTextAnnotation a5 = new CategoryTextAnnotation("5. Case studies are available.", "Category 5", 0.0); a5.setFont(new Font("SansSerif", Font.BOLD, 12)); a5.setTextAnchor(TextAnchor.BOTTOM_LEFT); a5.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a5); final CategoryTextAnnotation a6 = new CategoryTextAnnotation( "6. Case studies enhance users " + "understanding of the firm and its expertise.", "Category 6", 0.0); a6.setFont(new Font("SansSerif", Font.PLAIN, 12)); a6.setTextAnchor(TextAnchor.BOTTOM_LEFT); a6.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a6); final CategoryTextAnnotation a7 = new CategoryTextAnnotation( "7. Case studies are relevant to " + "the firm's prospects and clients.", "Category 7", 0.0); a7.setFont(new Font("SansSerif", Font.PLAIN, 12)); a7.setTextAnchor(TextAnchor.BOTTOM_LEFT); a7.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a7); final CategoryTextAnnotation a8 = new CategoryTextAnnotation( "8. White papers are relevant to the firm's positioning.", "Category 8", 0.0); a8.setFont(new Font("SansSerif", Font.PLAIN, 12)); a8.setTextAnchor(TextAnchor.BOTTOM_LEFT); a8.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a8); final CategoryTextAnnotation a9 = new CategoryTextAnnotation("9. Case studies are available.", "Category 9", 0.0); a9.setFont(new Font("SansSerif", Font.BOLD, 12)); a9.setTextAnchor(TextAnchor.BOTTOM_LEFT); a9.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a9); final CategoryTextAnnotation a10 = new CategoryTextAnnotation( "10. Case studies enhance users " + "understanding of the firm and its expertise.", "Category 10", 0.0); a10.setFont(new Font("SansSerif", Font.PLAIN, 12)); a10.setTextAnchor(TextAnchor.BOTTOM_LEFT); a10.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a10); final CategoryTextAnnotation a11 = new CategoryTextAnnotation( "11. Case studies are relevant " + "to the firm's prospects and clients.", "Category 11", 0.0); a11.setFont(new Font("SansSerif", Font.PLAIN, 12)); a11.setTextAnchor(TextAnchor.BOTTOM_LEFT); a11.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a11); final CategoryTextAnnotation a12 = new CategoryTextAnnotation( "12. White papers are relevant to the firm's positioning.", "Category 12", 0.0); a12.setFont(new Font("SansSerif", Font.PLAIN, 12)); a12.setTextAnchor(TextAnchor.BOTTOM_LEFT); a12.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a12); final CategoryTextAnnotation a13 = new CategoryTextAnnotation( "13. Users can easily access " + "resources based on viewer interest.", "Category 13", 0.0); a13.setFont(new Font("SansSerif", Font.BOLD, 12)); a13.setTextAnchor(TextAnchor.BOTTOM_LEFT); a13.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a13); final CategoryTextAnnotation a14 = new CategoryTextAnnotation( "14. Access to additional hyperlinks enhances users's ability to find relevant " + "information.", "Category 14", 0.0); a14.setFont(new Font("SansSerif", Font.BOLD, 12)); a14.setTextAnchor(TextAnchor.BOTTOM_LEFT); a14.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a14); final CategoryTextAnnotation a15 = new CategoryTextAnnotation("15. OVERALL EFFECTIVENESS.", "Overall", 0.0); a15.setFont(new Font("SansSerif", Font.BOLD, 12)); a15.setTextAnchor(TextAnchor.BOTTOM_LEFT); a15.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a15); return chart; }
From source file:org.talend.dataprofiler.chart.TOPChartService.java
@Override public void createAnnotOnGantt(Object chart, List<Object[]> rowList, int multiDateColumn, int nominal) { Map<String, RowColumPair> hightlightSeriesMap = new HashMap<String, RowColumPair>(); CategoryPlot xyplot = (CategoryPlot) ((JFreeChart) chart).getPlot(); CategoryTextAnnotation an; for (int seriesCount = 0; seriesCount < ((TaskSeriesCollection) xyplot.getDataset()) .getSeriesCount(); seriesCount++) { int indexOfRow = 0; int columnCount = 0; for (int itemCount = 0; itemCount < ((TaskSeriesCollection) xyplot.getDataset()).getSeries(seriesCount) .getItemCount(); itemCount++, columnCount++) { Task task = ((TaskSeriesCollection) xyplot.getDataset()).getSeries(seriesCount).get(itemCount); String taskDescription = task.getDescription(); String[] taskArray = taskDescription.split("\\|"); //$NON-NLS-1$ boolean isSameTime = task.getDuration().getStart().getTime() == task.getDuration().getEnd() .getTime();/*from w ww .j ava2s . c o m*/ if (!isSameTime && (rowList.get(indexOfRow))[multiDateColumn - 3] != null && (rowList.get(indexOfRow))[multiDateColumn - 2] != null && !((rowList.get(indexOfRow))[multiDateColumn]).equals(new BigDecimal(0L))) { RowColumPair pair = new RowColumPair(); pair.setRow(seriesCount); pair.setColumn(columnCount); hightlightSeriesMap.put(String.valueOf(seriesCount) + String.valueOf(columnCount), pair); an = new CategoryTextAnnotation("#nulls = " + (rowList.get(indexOfRow))[multiDateColumn], //$NON-NLS-1$ taskDescription, task.getDuration().getStart().getTime()); an.setTextAnchor(TextAnchor.CENTER_LEFT); an.setCategoryAnchor(CategoryAnchor.MIDDLE); xyplot.addAnnotation(an); } if (taskArray.length == nominal) { indexOfRow++; if (rowList.size() != indexOfRow && ((rowList.get(indexOfRow))[multiDateColumn - 3] == null || (rowList.get(indexOfRow))[multiDateColumn - 2] == null)) { indexOfRow++; } } } } CustomHideSeriesGanttRender renderer = new CustomHideSeriesGanttRender(hightlightSeriesMap); xyplot.setRenderer(renderer); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { TaskSeriesCollection taskSeriesColl = (TaskSeriesCollection) dataset; List<Task> taskList = new ArrayList<Task>(); for (int i = 0; i < taskSeriesColl.getSeriesCount(); i++) { for (int j = 0; j < taskSeriesColl.getSeries(i).getItemCount(); j++) { taskList.add(taskSeriesColl.getSeries(i).get(j)); } } Task task = taskList.get(column); // Task task = taskSeriesColl.getSeries(row).get(column); String taskDescription = task.getDescription(); Date startDate = task.getDuration().getStart(); Date endDate = task.getDuration().getEnd(); return taskDescription + ", " + startDate + "---->" + endDate; //$NON-NLS-1$ //$NON-NLS-2$ // return "this is a tooltip"; } }); xyplot.getDomainAxis().setMaximumCategoryLabelWidthRatio(10.0f); }