List of usage examples for org.jfree.chart.axis CategoryAxis getLabelFont
public Font getLabelFont()
From source file:net.sf.dynamicreports.design.transformation.chartcustomizer.GroupedStackedBarRendererCustomizer.java
@Override public void customize(JFreeChart chart, ReportParameters reportParameters) { this.seriesColors = new LinkedHashMap<String, Paint>(); this.map = null; Set<String> groups = new LinkedHashSet<String>(); CategoryDataset dataset = chart.getCategoryPlot().getDataset(); for (int i = 0; i < dataset.getRowCount(); i++) { String rowKey = (String) dataset.getRowKey(i); String group = StringUtils.substringBefore(rowKey, GROUP_SERIES_KEY); String series = StringUtils.substringAfter(rowKey, GROUP_SERIES_KEY); if (map == null) { map = new KeyToGroupMap(group); }// www. j ava 2 s .co m map.mapKeyToGroup(rowKey, group); groups.add(group); if (!seriesColors.containsKey(series)) { Paint paint = chart.getCategoryPlot().getDrawingSupplier().getNextPaint(); seriesColors.put(series, paint); } } DefaultCategoryDataset newDataset = new DefaultCategoryDataset(); for (Object column : dataset.getColumnKeys()) { for (String group : groups) { for (String series : seriesColors.keySet()) { try { Number value = dataset.getValue(group + GROUP_SERIES_KEY + series, (Comparable<?>) column); newDataset.addValue(value, group + GROUP_SERIES_KEY + series, (Comparable<?>) column); } catch (UnknownKeyException e) { newDataset.addValue(0, group + GROUP_SERIES_KEY + series, (Comparable<?>) column); } } } } dataset = newDataset; GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); renderer.setSeriesToGroupMap(map); StackedBarRenderer categoryRenderer = (StackedBarRenderer) chart.getCategoryPlot().getRenderer(); renderer.setBaseItemLabelsVisible(categoryRenderer.getBaseItemLabelsVisible()); renderer.setBaseItemLabelFont(categoryRenderer.getBaseItemLabelFont()); renderer.setBaseItemLabelPaint(categoryRenderer.getBaseItemLabelPaint()); renderer.setBaseItemLabelGenerator(categoryRenderer.getBaseItemLabelGenerator()); renderer.setShadowVisible(categoryRenderer.getShadowsVisible()); renderer.setItemMargin(0.10); renderer.setDrawBarOutline(false); for (int i = 0; i < dataset.getRowCount(); i++) { String rowKey = (String) dataset.getRowKey(i); String score = StringUtils.substringAfter(rowKey, GROUP_SERIES_KEY); renderer.setSeriesPaint(i, seriesColors.get(score)); } CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis(); SubCategoryAxis newDomainAxis = new SubCategoryAxis(domainAxis.getLabel()); newDomainAxis.setLabelFont(domainAxis.getLabelFont()); newDomainAxis.setTickLabelFont(domainAxis.getTickLabelFont()); newDomainAxis.setLabelPaint(domainAxis.getLabelPaint()); newDomainAxis.setTickLabelPaint(domainAxis.getTickLabelPaint()); newDomainAxis.setAxisLinePaint(domainAxis.getAxisLinePaint()); newDomainAxis.setTickMarkPaint(domainAxis.getTickMarkPaint()); newDomainAxis.setTickLabelsVisible(domainAxis.isTickLabelsVisible()); newDomainAxis.setTickMarksVisible(domainAxis.isTickMarksVisible()); newDomainAxis.setCategoryMargin(0.05); for (String group : groups) { newDomainAxis.addSubCategory(group); } CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainAxis(newDomainAxis); plot.setRenderer(renderer); LegendItemCollection legendItems = new LegendItemCollection(); for (String item : seriesColors.keySet()) { legendItems.add(new LegendItem(item, seriesColors.get(item))); } plot.setFixedLegendItems(legendItems); chart.getCategoryPlot().setDataset(dataset); }
From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeBarTimeChartData.java
@Override public JFreeChart getJFreeChart() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); double counts[] = ds.getCounts(); String legends[] = ds.getLegends(); int max_len = 0; for (int i = 0; i < ds.getNumSets(); i++) { if (legends != null && legends.length > i) { dataset.addValue(new Double(counts[i]), "Series-1", legends[i]); int leg_len = legends[i].length(); if (leg_len > max_len) { max_len = leg_len;//www . ja v a2 s . c o m } //System.out.println(legends[i] + counts[i]); } else { dataset.addValue(new Double(counts[i]), "Series-1", Integer.toString(i)); } } CategoryDataset data = dataset; JFreeChart chart = ChartFactory.createBarChart(title, null, quantity, data, PlotOrientation.VERTICAL, false, // include legends false, // tooltips false // urls ); CategoryPlot categoryPlot = chart.getCategoryPlot(); CategoryAxis axis = categoryPlot.getDomainAxis(); if (max_len > 8 || ds.getNumSets() > 16 || (max_len * ds.getNumSets()) > 50) { axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); } Font tickLabelFont = axis.getTickLabelFont(); if (ds.getNumSets() > 24) { axis.setTickLabelFont(tickLabelFont.deriveFont(tickLabelFont.getSize() - 2.0F)); } Font labelFont = axis.getLabelFont(); axis.setMaximumCategoryLabelLines(3); //axis.setLabelFont(labelFont.d); // axis.setLabel("Pingu"); This works so we can modify return chart; }
From source file:org.forester.archaeopteryx.TreePanel.java
private static JFreeChart createChart(CategoryDataset dataset, String branch_name) { // create the chart JFreeChart chart = ChartFactory.createBarChart("RAxML Weights Histogram " + branch_name, // chart title "RAxML Weights", // domain axis label "Placements", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? );//from www .ja v a 2 s. co m // set the background color for the chart and title colors & font chart.setBackgroundPaint(Color.black); chart.setTextAntiAlias(true); chart.setBorderPaint(Color.green); chart.getTitle().setPaint(Color.white); chart.getTitle().setFont(chart.getTitle().getFont().deriveFont(12.0f)); // get a reference to the plot for further customisation CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(0.7f); plot.setBackgroundPaint(Color.black); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only, set colors & font final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelPaint(Color.white); rangeAxis.setLabelFont(rangeAxis.getLabelFont().deriveFont(10.0f)); rangeAxis.setAxisLinePaint(new Color(226, 236, 243)); rangeAxis.setTickLabelFont(rangeAxis.getTickLabelFont().deriveFont(8.0f)); rangeAxis.setTickLabelPaint(Color.white); // Custom renderer to display each bar in another color final BarRenderer renderer = new CustomRenderer(new Paint[] { new Color(255, 0, 0), new Color(227, 28, 0), new Color(199, 56, 0), new Color(171, 84, 0), new Color(143, 112, 0), new Color(115, 140, 0), new Color(87, 168, 0), new Color(59, 196, 0), new Color(31, 224, 0), new Color(0, 255, 0) }); // shadow effect off renderer.setShadowVisible(false); //make custom renderer the new renderer for the barchart plot.setRenderer(renderer); // set x axis label rotation, font and color CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4)); domainAxis.setLabelPaint(Color.white); domainAxis.setLabelFont(domainAxis.getLabelFont().deriveFont(10.0f)); domainAxis.setTickLabelPaint(Color.white); domainAxis.setTickLabelFont(domainAxis.getTickLabelFont().deriveFont(8.0f)); domainAxis.setAxisLinePaint(new Color(226, 236, 243)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }