Dynamically creating any number of graphs?

Help
2009-01-14
2013-01-13
  • Josh Harris
    Josh Harris
    2009-01-14

    I am looking at creating any number of graphs based on user input with data based on user input.  These graphs will show different statistics gathered from jmx mbeans on jvms from a number of different servers.  The user will pick which statistics (graphs) to display for which jvms they want.
    This means there will be a dynamic number of dynamic graphs. 

    My current approach is to use a String buffer to build the cewolf chart structure and pass it to the jsp after clicking a button.  The problem is the graph wont show up even know the code is there.  I am guessing this is happening because the chart gets rendered before the string is retrieved from the session. 

    Anyone know what I am doing wrong, or the more likely answer of a better way to do it?

    Example of one chart:

    <td>
             ${chart}
    </td>

    Turns into

    <td>
    <cewolf:chart id="line" title="Heap Size" type="line" xaxislabel="Minutes" yaxislabel="Heap Size (kB)">   
            <cewolf:data>       
                <cewolf:producer id="heapSizeView">
                  <cewolf:param name="jvmId" value="<%=1%>"/>
                  <cewolf:param name="statId" value="<%=1%>"/>
                  <cewolf:param name="start" value="<%=1231498624000%>"/>
                  <cewolf:param name="end" value="<%=1231499209000%>"/>
            </cewolf:producer>
            </cewolf:data>
    </cewolf:chart>
    <cewolf:img chartid="line" renderer="cewolf" width="500" height="300"/>
    </td>

     
    • Ulf Dittmer
      Ulf Dittmer
      2009-01-15

      No, this approach is not going to work. What you're doing is to add something to the page output that needs to be part of the page from the beginning.

      You need to put the cewolf tags in the JSP page, and then fill in any variables in a loop, probably a JSTL c:forEach loop over a collection of some kind that contains those values.

       
    • Josh Harris
      Josh Harris
      2009-01-15

      Is there anyway to add graphs on demand? Seems like you will have to have a static number of graphs.

      Thanks for answering.

       
    • Ulf Dittmer
      Ulf Dittmer
      2009-01-15

      I think you need to be more specific about what you mean by "on demand". As I said, if you create the cewolf tags in a JSTL loop, then it's a runtime decision how many charts will be created.

       
    • Josh Harris
      Josh Harris
      2009-01-16

      Oh right, thanks.  That should work.

       
    • Josh Harris
      Josh Harris
      2009-01-21

      So I was trying to get cewolf working with the jstl foreach loop and when the loop gets to <cewolf:chart tag I get this exception:

      org.apache.jasper.JasperException: /WEB-INF/jsp/index.jsp(77,30) Unterminated &lt;cewolf:chart tag
          org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
          org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
          org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:132)
          org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:994)
          org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1272)
          org.apache.jasper.compiler.Parser.parseElements(Parser.java:1449)
          org.apache.jasper.compiler.Parser.parseBody(Parser.java:1657)
          org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:1004)
          org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1272)
          org.apache.jasper.compiler.Parser.parseElements(Parser.java:1449)
          org.apache.jasper.compiler.Parser.parseBody(Parser.java:1657)
          org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:1004)
          org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1272)
          org.apache.jasper.compiler.Parser.parseElements(Parser.java:1449)
          org.apache.jasper.compiler.Parser.parse(Parser.java:133)
          org.apache.jasper.compiler.ParserController.doParse(ParserController.java:216)
          org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
          org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:167)
          org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
          org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
          org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
          org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
          org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
          org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
          org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
          javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
          control.Controller.doGet(Controller.java:53)
          javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
          javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

      This is the code I am using

      <c:forEach var="graph" items="${jvmGraphs.graphs}">
          <td>
              <cewolf:chart
                  id="<c:out value="${graph.chartId}"/>"
                  title="<c:out value="${graph.chartTitle}"/>"
                  type="<c:out value="${graph.chartType}"/>"
                  xaxislabel="<c:out value="${graph.xaxislabel}"/>"
                  yaxislabel="<c:out value="${graph.yaxislabel}"/>">   
                  <cewolf:data>       
                      <cewolf:producer id="<c:out value="${graph.producerId}"/>">
                            <cewolf:param name="jvmId" value="<c:out value="${graph.jvmId}"/>"/>
                            <cewolf:param name="statId" value="<c:out value="${graph.statId}"/>"/>
                            <cewolf:param name="start" value="<c:out value="${graph.startTime}"/>"/>
                            <cewolf:param name="end" value="<c:out value="${graph.endTime}"/>"/>
                      </cewolf:producer>
                  </cewolf:data>
              </cewolf:chart>
              <cewolf:img
                  chartid="<c:out value="${graph.chartId}"/>"
                  renderer="<c:out value="${graph.chartImgRenderer}"/>"
                  width="<c:out value="${graph.chartImgWidth}"/>"
                  height="<c:out value="${graph.chartImgHeight}"/>"/>
          </td>
      </c:forEach>