Display value with line chart datapoints

Help
2007-01-24
2013-01-13
  • shwetagupta
    shwetagupta
    2007-01-24

    Hi,

    I have successfully drawn the line chart using cewolf .But the problem is i need to show the values as datapoints.

    My Jsp code is :

    <%
    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.setShapesVisible(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="package1.PageViewChartApp" />
    <cewolf:chart    id="line"     title="Demand to ForeCast"    type="line"     xaxislabel="Time(Monthly)"     yaxislabel="Volume">   
        <cewolf:data>       
            <cewolf:producer id="pageViews"/> 
        </cewolf:data>
       
        <cewolf:chartpostprocessor id="test">
       </cewolf:chartpostprocessor>
       
    </cewolf:chart><p>
    <cewolf:img chartid="line" renderer="/cewolf" width="400" height="300" alt="pageViews">
        <cewolf:map tooltipgeneratorid="pageViews"/>
    </cewolf:img> 

    AND my java code is:

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

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

        // 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[] categories =    {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"};
        private final String[] seriesNames =    {"2004 Actual", "2004 Forecast", "2004 Deviation"};
           
             
        /**
         *  Produces some random data.
         */
        public Object produceDataset(Map params) throws DatasetProduceException {
            log.debug("producing data.");
            //DefaultCategoryDataset dataset = new DefaultCategoryDataset(){
                /**
                 * @see java.lang.Object#finalize()
                 */
                //protected void finalize() throws Throwable {
                //    super.finalize();
                //    log.debug(this +" finalized.");
                //}
            //};
            DefaultCategoryDataset dataset = new DefaultCategoryDataset();
                   
            double series0[] = {1806, 1731, 1733, 1904, 2036, 2560, 2679, 2821, 2359, 2160, 1802, 1853};//Actual data
               
                for(int i=0;i<series0.length;i++)
                {
                    dataset.addValue(series0[i],seriesNames[0],categories[i]);
                }
          
           
                     double series1[] = {2263.19696969697, 2308.02214452214, 2352.84731934732, 2397.67249417249, 2442.49766899767, 2487.32284382284, 2532.14801864802, 2576.97319347319, 2621.79836829837, 2666.62354312354, 2711.44871794872, 2756.27389277389};//ForeCast data
            
                for(int i=0;i<series1.length;i++)
                {
                    dataset.addValue(series1[i],seriesNames[1],categories[i]);
                }
            double series2[] = new double[12];
            for(int i=0;i<series1.length;i++)
            {
                series2[i] = series1[i] - series0[i];//Deviation= Forecast - Actual
            }
           
                        for(int i=0;i<series2.length;i++)
                {
                    dataset.addValue(series2[i],seriesNames[2],categories[i]);
                }
                    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;
            return true;
        }

        /**
         * Returns a unique ID for this DatasetProducer
         */
        public String getProducerId() {
            return "PageViewChartApp 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];
        }

       
    }

    But i didn't able to display values with the line points.I mean values being set in series[0],series[1],series[2] should be displayed in the graph at those points.

    Please reply soon if anybody knows...

     
    • shwetagupta
      shwetagupta
      2007-01-25

      Here

      setItemLabelsVisible(true) in jsp is not working....
      It is not making any difference whether i make it true or false....
      May be it is now supported by Cewolf.

      Can anyone have any other solution.Please tel me if anyone comes to know anything.

      Thanks