01: package de.laures.cewolf.cpp;
02:
03: import java.util.Map;
04:
05: import org.jfree.chart.JFreeChart;
06: import org.jfree.chart.axis.CategoryAxis;
07: import org.jfree.chart.axis.CategoryLabelPositions;
08: import org.jfree.chart.plot.CategoryPlot;
09: import org.jfree.data.category.CategoryDataset;
10:
11: import de.laures.cewolf.ChartPostProcessor;
12:
13: /**
14: * A cewolf post-processor for rotating and/or removing the labels on the X-Axis
15: * parameters:
16: * rotate_at: make the labels vertical
17: * skip_at: print only some of the labels (so they don't overlap)
18: * remove_at: don't print any labels
19: *
20: * Usage:
21: * <chart:chartpostprocessor id="labelRotation">
22: * <chart:param name="rotate_at" value='<%= new Integer(10) %>'/>
23: * <chart:param name="skip_at" value='<%= new Integer(50) %>'/>
24: * <chart:param name="remove_at" value='<%= new Integer(100) %>'/>
25: * </chart:chartpostprocessor>
26: *
27: *
28: * @author Rich Unger
29: */
30:
31: public class RotatedAxisLabels implements ChartPostProcessor {
32:
33: public void processChart(Object chart, Map params) {
34: CategoryPlot plot = (CategoryPlot) ((JFreeChart) chart)
35: .getPlot();
36:
37: CategoryAxis axis = plot.getDomainAxis();
38:
39: Number rotateThreshold = (Number) params.get("rotate_at");
40: Number skipThreshold = (Number) params.get("skip_at");
41: Number removeThreshold = (Number) params.get("remove_at");
42:
43: CategoryDataset dataset = plot.getDataset();
44: int iCategoryCount = dataset.getRowCount();
45:
46: if (rotateThreshold != null) {
47: if (iCategoryCount >= rotateThreshold.intValue()) {
48: axis
49: .setCategoryLabelPositions(CategoryLabelPositions.UP_90);
50: } else {
51: axis
52: .setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
53: }
54:
55: }
56:
57: if (skipThreshold != null) {
58: //this method does nothing in jfreechart .9.18
59: //axis.setSkipCategoryLabelsToFit(iCategoryCount >= skipThreshold.intValue());
60: }
61:
62: if (removeThreshold != null) {
63: axis.setTickLabelsVisible(iCategoryCount < removeThreshold
64: .intValue());
65: }
66: }
67:
68: }
|