CeWolf - setItemLabelsVisible not supported??

patrick
2005-11-17
2013-01-13
  • patrick
    patrick
    2005-11-17

    Hello,

    I tried creating a LineChart with CeWolf:

    The first is the jsp-site

    <%@page contentType="text/html"%>
    <%@taglib uri='/WEB-INF/cewolf.tld' prefix='cewolf' %>
    <%@page import="java.util.*"%>
    <%@page import="de.laures.cewolf.*"%>
    <%@page import="de.laures.cewolf.tooltips.*"%>
    <%@page import="de.laures.cewolf.links.*"%>
    <%@page import="org.jfree.data.*"%>
    <%@page import="org.jfree.data.time.*"%>
    <%@page import="org.jfree.data.gantt.*"%>
    <%@page import="org.jfree.chart.*"%>
    <%@page import="org.jfree.chart.plot.*"%>
    <%@page import="org.jfree.data.category.*"%>
    <%@page import="org.jfree.data.general.*"%>
    <%@page import="org.jfree.data.xy.*"%>
    <%@page import="java.awt.*" %>
    <%@page import="org.jfree.chart.*" %>
    <%@page import="org.jfree.chart.labels.*" %>
    <%@page import="org.jfree.chart.axis.NumberAxis" %>
    <%@page import="org.jfree.chart.plot.*" %>
    <%@page import="org.jfree.chart.renderer.*" %>
    <%@page import="org.jfree.chart.renderer.category.*" %>
    <%@page import="org.jfree.data.*" %>
    <HTML>
    <BODY>
    <H1>Page View Statistics</H1>
    <HR>
    <%
    ChartPostProcessor meterPP = new ChartPostProcessor() {
       
            public void processChart(Object chart, Map params)
            {
                JFreeChart chart1 = (JFreeChart)chart;
                chart1.setBackgroundPaint(new Color(0xC0, 0xC0, 0xC0));
                CategoryPlot plot = chart1.getCategoryPlot();
                // customise the range axis...
            NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            rangeAxis.setAutoRangeIncludesZero(true);
            rangeAxis.setUpperMargin(0.20);
            rangeAxis.setLabelAngle(Math.PI / 2.0);
           
            // customise the renderer...
            LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
            renderer.setDrawShapes(true);
            renderer.setPositiveItemLabelPosition(new ItemLabelPosition());
            renderer.setNegativeItemLabelPosition(new ItemLabelPosition());
            renderer.setItemLabelsVisible(true);
            chart1.getCategoryPlot().setRenderer(renderer);
           
            }   
        };
        pageContext.setAttribute("test", meterPP);
    %>
    <jsp:useBean id="pageViews" class="de.laures.cewolf.example.PageViewCountData"/>
    <cewolf:chart
        id="line"
        title="Page View Statistics"
        type="line"
        xaxislabel="Euro"
        yaxislabel="Jahre">
        <cewolf:data>
            <cewolf:producer id="pageViews"/>
        </cewolf:data>
        <cewolf:chartpostprocessor id="test">
       </cewolf:chartpostprocessor>
    </cewolf:chart>

    <cewolf:img chartid="line" renderer="cewolf" width="400" height="300"/>

    </BODY> </HTML>

    Ant the class with the sample data:

    public class PageViewCountData implements DatasetProducer, CategoryToolTipGenerator, CategoryItemLinkGenerator, Serializable {

        private static final Log log = LogFactory.getLog(PageViewCountData.class);

        double [] zinsen = new double[5];
        String [] jahre = new String[5];
        double [] tilgung = new double[5];
        double [] restschuld = new double[5];
       
        // These values would normally not be hard coded but produced by
        // some kind of data source like a database or a file
        private final String[] seriesNames =    {"Zinsen", "Tilgung", "Restschuld"};

        /**
         *  Produces some random data.
         */
        public Object produceDataset(Map params) throws DatasetProduceException
        {
           
            // column keys...
            for(int k = 0; k < jahre.length; k++)
            {
                jahre[k] = (k+1)+". Jahr";
            }
           
            zinsen[0] = 49500.0;
            zinsen[1] = 41228.92;
            zinsen[2] = 32213.45;
            zinsen[3] = 22386.58;
            zinsen[4] = 11675.3;
           
            tilgung[0] = 91900.85;
            tilgung[1] = 100171.93;
            tilgung[2] = 109187.4;
            tilgung[3] = 119014.27;
            tilgung[4] = 129725.55;
           
            restschuld[0] = 458099.15;
            restschuld[1] = 357927.22;
            restschuld[2] = 248739.82;
            restschuld[3] = 129725.55;
            restschuld[4] = 0.0;
           
            // create the dataset...
            DefaultCategoryDataset dataset = new DefaultCategoryDataset();
           
            for(int i = 0; i < jahre.length; i++)
            {
                dataset.addValue(zinsen[i], seriesNames[0], jahre[i]);
            }
           
            for(int m = 0; m < jahre.length; m++)
            {
                dataset.addValue(tilgung[m], seriesNames[1], jahre[m]);
            }
           
            for(int k = 0; k < jahre.length; k++)
            {
                dataset.addValue(restschuld[k], seriesNames[2], jahre[k]);
            }
           
            return dataset;
        }

        /**
         * This producer's data is invalidated after 5 seconds. By this method the
         * producer can influence Cewolf's caching behaviour the way it wants to.
         */
        public boolean hasExpired(Map params, Date since) {       
            log.debug(getClass().getName() + "hasExpired()");
            return (System.currentTimeMillis() - since.getTime())  > 5000;
        }

        /**
         * Returns a unique ID for this DatasetProducer
         */
        public String getProducerId() {
            return "PageViewCountData DatasetProducer";
        }

        /**
         * Returns a link target for a special data item.
         */
        public String generateLink(Object data, int series, Object category) {
            return seriesNames[series];
        }
       
        /**
         * @see java.lang.Object#finalize()
         */
        protected void finalize() throws Throwable {
            super.finalize();
            log.debug(this + " finalized.");
        }

        /**
         * @see org.jfree.chart.tooltips.CategoryToolTipGenerator#generateToolTip(CategoryDataset, int, int)
         */
        public String generateToolTip(CategoryDataset arg0, int series, int arg2) {
            return seriesNames[series];
        }

    }

    The sample works without problems but the setItemLabelsVisible(true) of the LineAndShapeRenderer is not applied to the lineChart. Has anyone tried that yet? The method should cause that the values of the items on the lines will displayed.

    Has anyone a solution for that problem?

    thanks in advance

    kind regards

    pat