List of usage examples for org.jfree.chart.axis CategoryAxis getLabel
public String getLabel()
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); }/*from ww w . j a v a2 s.c o 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:br.upe.ecomp.dosa.controller.chart.FileBoxplotChartManager.java
private JFreeChart createChart(String title, String xLabel, String yLabel, BoxAndWhiskerCategoryDataset dataset, boolean logarithmicYAxis) { final CategoryAxis xAxis = new CategoryAxis("Sample"); final NumberAxis yAxis; if (logarithmicYAxis) { yAxis = new LogarithmicAxis("Fitness (Log10)"); ((LogarithmicAxis) yAxis).setExpTickLabelsFlag(true); } else {// w w w . j a va 2 s. c o m yAxis = new NumberAxis("Fitness"); } yAxis.setAutoRangeIncludesZero(false); yAxis.setAutoRange(true); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(true); renderer.setBaseCreateEntities(true); // renderer.setArtifactPaint(Color.green); renderer.setBaseOutlinePaint(Color.blue); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(title, xAxis.getLabel(), yAxis.getLabel(), dataset, true); final CategoryPlot plot = chart.getCategoryPlot();// new CategoryPlot(dataset, xAxis, yAxis, // renderer); plot.setBackgroundPaint(Color.white); // chart.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); plot.setRenderer(renderer); plot.setRangeAxis(yAxis); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
From source file:lucee.runtime.tag.Chart.java
private void setLabelFormat(JFreeChart chart) { Plot plot = chart.getPlot();// w w w . j a v a 2 s. co m if (plot instanceof CategoryPlot) { CategoryPlot cp = (CategoryPlot) plot; ValueAxis rangeAxis = cp.getRangeAxis(); rangeAxis.setAutoTickUnitSelection(true); rangeAxis.setStandardTickUnits(new TickUnitsImpl(rangeAxis.getStandardTickUnits(), labelFormat)); CategoryItemRenderer r = cp.getRenderer(); r.setBaseItemLabelsVisible(false); CategoryAxis da = cp.getDomainAxis(); if (!showXLabel) da.setTickLabelsVisible(false); da.setCategoryLabelPositions(labelPosition); da.setMaximumCategoryLabelWidthRatio(100); //da.setVisible(false); } if (plot instanceof XYPlot) { XYPlot cp = (XYPlot) plot; ValueAxis rangeAxis = cp.getRangeAxis(); rangeAxis.setAutoTickUnitSelection(true); rangeAxis.setStandardTickUnits(new TickUnitsImpl(rangeAxis.getStandardTickUnits(), labelFormat)); XYItemRenderer r = cp.getRenderer(); r.setBaseItemLabelsVisible(false); ValueAxis da = cp.getDomainAxis(); if (!_plotItemLables.isEmpty()) { _plotItemLables.add(0, ""); String[] cols = _plotItemLables.toArray(new String[_plotItemLables.size()]); SymbolAxis sa = new SymbolAxis(da.getLabel(), cols); sa.setRange(da.getRange()); if (labelPosition == LABEL_VERTICAL) { sa.setVerticalTickLabels(true); } cp.setDomainAxis(sa); } if (!showXLabel) cp.getDomainAxis().setTickLabelsVisible(false); //da.setVisible(false); } }