franta-hg@1: package de.laures.cewolf.cpp; franta-hg@1: franta-hg@1: import java.util.Map; franta-hg@1: franta-hg@1: import org.jfree.chart.JFreeChart; franta-hg@1: import org.jfree.chart.axis.CategoryAxis; franta-hg@1: import org.jfree.chart.axis.CategoryLabelPositions; franta-hg@1: import org.jfree.chart.plot.CategoryPlot; franta-hg@1: import org.jfree.data.category.CategoryDataset; franta-hg@1: franta-hg@1: import de.laures.cewolf.ChartPostProcessor; franta-hg@1: franta-hg@1: /** franta-hg@1: * A cewolf post-processor for rotating and/or removing the labels on the X-Axis franta-hg@1: * parameters: franta-hg@1: * rotate_at: make the labels vertical franta-hg@1: * skip_at: print only some of the labels (so they don't overlap) franta-hg@1: * remove_at: don't print any labels franta-hg@1: * franta-hg@1: * Usage: franta-hg@1: * franta-hg@1: * franta-hg@1: * franta-hg@1: * franta-hg@1: * franta-hg@1: * franta-hg@1: * franta-hg@1: * @author Rich Unger franta-hg@1: */ franta-hg@1: franta-hg@1: public class RotatedAxisLabels implements ChartPostProcessor { franta-hg@1: franta-hg@1: public void processChart(Object chart, Map params) { franta-hg@1: CategoryPlot plot = (CategoryPlot) ((JFreeChart) chart).getPlot(); franta-hg@1: franta-hg@1: CategoryAxis axis = plot.getDomainAxis(); franta-hg@1: franta-hg@1: Number rotateThreshold = (Number) params.get("rotate_at"); franta-hg@1: Number skipThreshold = (Number) params.get("skip_at"); franta-hg@1: Number removeThreshold = (Number) params.get("remove_at"); franta-hg@1: franta-hg@1: CategoryDataset dataset = plot.getDataset(); franta-hg@1: int iCategoryCount = dataset.getRowCount(); franta-hg@1: franta-hg@1: if (rotateThreshold != null) franta-hg@1: { franta-hg@1: if (iCategoryCount >= rotateThreshold.intValue()) franta-hg@1: { franta-hg@1: axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); franta-hg@1: } franta-hg@1: else franta-hg@1: { franta-hg@1: axis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD); franta-hg@1: } franta-hg@1: franta-hg@1: } franta-hg@1: franta-hg@1: if (skipThreshold != null) franta-hg@1: { franta-hg@1: //this method does nothing in jfreechart .9.18 franta-hg@1: //axis.setSkipCategoryLabelsToFit(iCategoryCount >= skipThreshold.intValue()); franta-hg@1: } franta-hg@1: franta-hg@1: if (removeThreshold != null) franta-hg@1: { franta-hg@1: axis.setTickLabelsVisible(iCategoryCount < removeThreshold.intValue()); franta-hg@1: } franta-hg@1: } franta-hg@1: franta-hg@1: }