which object has to return to DatasetProducer

Help
scheduler
2007-03-08
2013-01-13
  • scheduler
    scheduler
    2007-03-08

    in the below code i am not able to know that which object has to be return to DatasetProducer. and that should be given as the id to cewolf tags. please help me at this point.

    the code i have return is

    please help me. i am trying it from 5 days to resolve it. waiting for reply now please.

    <%@ page import="de.laures.cewolf.DatasetProducer"%>

    <%@ page import="java.awt.Color"%>
    <%@ page import="java.awt.GradientPaint"%>
    <%@ page import="java.awt.Paint"%>
    <%@ page import="java.io.File"%>
    <%@ page import="java.util.Map"%>
    <%@ page import="java.util.Date"%>

    <%@ page import="org.jfree.chart.ChartFactory"%>
    <%@ page import="org.jfree.chart.ChartUtilities"%>
    <%@ page import="org.jfree.chart.JFreeChart"%>
    <%@ page import="org.jfree.chart.axis.SubCategoryAxis"%>
    <%@ page import="org.jfree.chart.plot.CategoryPlot"%>
    <%@ page import="org.jfree.chart.plot.PlotOrientation"%>
    <%@ page import="org.jfree.chart.renderer.category.GroupedStackedBarRenderer"%>
    <%@ page import="org.jfree.data.KeyToGroupMap"%>
    <%@ page import="org.jfree.data.category.DefaultCategoryDataset"%>
    <%@ page import="org.jfree.ui.GradientPaintTransformType"%>
    <%@ page import="org.jfree.ui.StandardGradientPaintTransformer"%>

    <%@ page import="de.laures.cewolf.DatasetProduceException"%>
    <%@ page import="de.laures.cewolf.DatasetProducer"%>

    <%@page contentType="text/html"%>
    <%@taglib uri='/WEB-INF/cewolf.tld' prefix='cewolf' %>
    <%
    if (pageContext.getAttribute("initFlag") == null)
    {

    DatasetProducer categoryData = new DatasetProducer()
    {
    public DefaultCategoryDataset result=null;
    private static final long serialVersionUID = 1L;

    public Object produceDataset(Map params) throws DatasetProduceException
    {

    result = new DefaultCategoryDataset();

    result.addValue(1, "a", "1");
    result.addValue(1, "a", "2");
    result.addValue(1, "a", "3");

    result.addValue(1, "b", "1");
    result.addValue(1, "b", "2");
    result.addValue(1, "b", "3");

    result.addValue(1, "c", "1");
    result.addValue(1, "c", "2");
    result.addValue(1, "c", "3");

    result.addValue(1, "d", "1");
    result.addValue(1, "d", "2");
    result.addValue(1, "d", "3");

    result.addValue(1, "e", "1");
    result.addValue(1, "e", "2");
    result.addValue(1, "e", "3");

    result.addValue(1, "f", "1");
    result.addValue(1, "f", "2");
    result.addValue(1, "f", "3");

    result.addValue(1, "g", "1");
    result.addValue(1, "g", "2");
    result.addValue(1, "g", "3");

    result.addValue(1, "h", "1");
    result.addValue(1, "h", "2");
    result.addValue(1, "h", "3");

    final JFreeChart chart = ChartFactory.createStackedBarChart(
    "Stacked Bar Chart Demo 5", // chart title
    "Category", // domain axis label
    "Value", // range axis label
    result, // data
    PlotOrientation.VERTICAL, // the plot orientation
    true, // legend
    true, // tooltips
    false // urls
    );

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();

    KeyToGroupMap map = new KeyToGroupMap("G1");

    map.mapKeyToGroup("a", "G1");
    map.mapKeyToGroup("b", "G1");
    map.mapKeyToGroup("c", "G1");
    map.mapKeyToGroup("d", "G1");
    map.mapKeyToGroup("e", "G1");
    map.mapKeyToGroup("f", "G1");
    map.mapKeyToGroup("g", "G1");
    map.mapKeyToGroup("h", "G1");

    renderer.setSeriesToGroupMap(map);

    renderer.setItemMargin(0.0);
    Paint p1 = new GradientPaint(
    0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f, new Color(0x88, 0xFF, 0x88)
    );

    Paint p2 = new GradientPaint(
    0.0f, 0.0f, new Color(0x00, 0x00, 0x00), 0.0f, 0.0f, new Color(0x00, 0x00, 0x00)
    );

    Paint p3 = new GradientPaint(
    0.0f, 0.0f, new Color(0x22, 0x22, 0x22), 0.0f, 0.0f, new Color(0x22, 0x22, 0x22)
    );

    renderer.setSeriesPaint(0, p1);
    renderer.setSeriesPaint(1, p1);
    renderer.setSeriesPaint(2, p1);
    renderer.setSeriesPaint(3, p1);
    renderer.setSeriesPaint(4, p1);
    renderer.setSeriesPaint(5, p1);
    renderer.setSeriesPaint(6, p1);
    renderer.setSeriesPaint(7, p1);

    renderer.setSeriesPaint(8, p2);
    renderer.setSeriesPaint(9, p2);
    renderer.setSeriesPaint(10, p2);
    renderer.setSeriesPaint(11, p2);
    renderer.setSeriesPaint(12, p2);
    renderer.setSeriesPaint(13, p2);
    renderer.setSeriesPaint(14, p2);
    renderer.setSeriesPaint(15, p2);

    renderer.setSeriesPaint(16, p3);
    renderer.setSeriesPaint(17, p3);
    renderer.setSeriesPaint(18, p3);
    renderer.setSeriesPaint(19, p3);
    renderer.setSeriesPaint(20, p3);
    renderer.setSeriesPaint(21, p3);
    renderer.setSeriesPaint(22, p3);
    renderer.setSeriesPaint(23, p3);

    renderer.setGradientPaintTransformer(
    new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)
    );

    SubCategoryAxis domainAxis = new SubCategoryAxis("Product / Month");
    domainAxis.setCategoryMargin(.50);
    domainAxis.addSubCategory("");

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainAxis(domainAxis);
    //plot.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
    plot.setRenderer(renderer);
    try{
    ChartUtilities.saveChartAsJPEG(new File("d:Examples/chart456.jpg"),chart,500,300);
    System.out.println("Executed");
    }

    catch(Exception e)
    {
    System.out.println(e);
    }
    return chart;
    }

    public String getProducerId()
    {
    return null;
    }

    public boolean hasExpired(Map arg0, Date arg1)
    {
    return false;
    }
    };
    pageContext.setAttribute("CD", categoryData);
    // DatasetProducer dp=(DatasetProducer)request.getAttribute("ChartDataset");
    //pageContext.setAttribute("DP", dp);
    }
    %>
    <html>
    <head>
    <BODY bgcolor="#DDE8F2">
    <H1 align="center">My Sample Chart</H1>
    <p>
    <table border=0 align="center"%>
    <TR>
    <TD><BR>
    <cewolf:chart id="stackedVerticalBar"
    title="StackedVerticalBar"
    type="StackedVerticalBar"
    xaxislabel="Threads"
    yaxislabel="Jobs">

    <cewolf:data>
    <cewolf:producer id="CD" />
    </cewolf:data>

    </cewolf:chart>

    <cewolf:img chartid="stackedVerticalBar" renderer="/cewolf" width="700" height="300"/>
    </TD>
    </TR>
    </TABLE>
    </body>
    </html>

    and the exception i got for this code is ClassCastException
    java.lang.ClassCastException raised:
    org.jfree.chart.JFreeChart

    java.lanag.ClassCastException:org.jfree.chart.JFreeChart
    at de.laures.cewolf.taglib.DataContainer.getDataset(DataContainer.java:53)
    at de.laures.cewolf.taglib.SimpleChartDefinition.getDataset(SimpleChartDefinition.java:34)
    at de.laures.cewolf.taglib.SimpleChartDefinition.produceChart(SimpleChartDefinition.java:30)
    at de.laures.cewolf.taglib.AbstractChartDefinition.getChart(AbstractChartDefinition.java:121)
    at de.laures.cewolf.taglib.ChartImageDefinition.ensureRendered(ChartImageDefintion.java:137)
    at de.laures.cewolf.taglib.ChartImageDefinition.getSize(ChartImageDefintion.java:148)
    at de.laures.cewolf.CewolfRenderer.doGet(CewolfRenderer.java:153)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValue.invoke(StandardWrapperValue.java:213)
    at org.apache.catalina.core.StandardContextValue.invoke(StandardContextValue.java:178)
    at org.apache.catalina.core.StandardHostValue.invoke(StandardHostValue.java:126)
    at org.apache.catalina.values.ErrorReportValue.invoke(ErrorReportValue.java:105)
    at org.apache.catalina.core.StandardEngineValue.invoke(StandardEngineValue.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)