This the servlet i have made now and trying to make a chart.

public class Beat extends HttpServlet implements DataTableGenerator {

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

   //  * Processes requests for both HTTP <code>GET</code> and
<code>POST</code> methods.
 protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

       DataTable data = generateDataTable(null, request);
 try {
           // /* TODO output your page here
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet Beat</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet Beat at " +
request.getContextPath () + "</h1>");
            out.println("</body>");
            out.println("</html>");

DataSourceHelper.executeDataSourceServletFlow(request, response,
(DataTableGenerator)generateDataTable(null, request),Boolean.FALSE);

/// sending to html to draw the chart // the html code is fine too
       RequestDispatcher rd;
        rd = request.getRequestDispatcher("newhtml.html");
        rd.include(request, response);        ////forward(request, response);

} finally {
            out.close();
        }
    }

     public DataTable generateDataTable(Query query,
HttpServletRequest request) {
    // Create a data table.
    DataTable data = new DataTable();
    ArrayList<ColumnDescription> cd = new
ArrayList<ColumnDescription>();
    cd.add(new ColumnDescription("name", ValueType.TEXT, "Animal
name"));
    cd.add(new ColumnDescription("link", ValueType.TEXT, "Link to
wikipedia"));
    cd.add(new ColumnDescription("population", ValueType.NUMBER,
"Population size"));
    cd.add(new ColumnDescription("vegeterian", ValueType.BOOLEAN,
"Vegetarian?"));

    data.addColumns(cd);

    // Fill the data table.
    try {
      data.addRowFromValues("Aye-aye", "http://en.wikipedia.org/wiki/
Aye-aye", 100, true);
      data.addRowFromValues("Sloth", "http://en.wikipedia.org/wiki/
Sloth", 300, true);
      data.addRowFromValues("Leopard", "http://en.wikipedia.org/wiki/
Leopard", 50, false);
      data.addRowFromValues("Tiger", "http://en.wikipedia.org/wiki/
Tiger", 80, false);
    } catch (TypeMismatchException e) {
      System.out.println("Invalid type!");
    }
    return data;
  }

      public Capabilities getCapabilities(){
          return Capabilities.NONE;
      }

      protected boolean isRestrictedAccessMode() {
         return false;
      }

  @Override
    protected void doGet(HttpServletRequest request,
HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
 @Override
    protected void doPost(HttpServletRequest request,
HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }


I am not able to draw the chart.
I want to draw the chart at one url hit how can i do
please guide me

On Jun 10, 12:00 pm, Akku <[email protected]> wrote:
> ok
> I run this code
>
> http://code.google.com/apis/visualization/documentation/dev/dsl_csv.h...
>
> when I hit the address I get the following result
>
> ............................................}]},{c:[{v:'Tiger'},
> {v:'http://en.wikipedia.org/wiki/Tiger'},{v:80.0},{v:false}]} which is
> ok
>
> then i run the following code
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <!DOCTYPE html>
> <html>
> <head>
>   <title>Getting Started Example</title>
>   <!--Load the AJAX API-->
>   <script type="text/javascript" src="http://www.google.com/jsapi";></
> script>
>   <script type="text/javascript">
>
>   //Load the Visualization API and the ready-made Google table
> visualization
>   google.load('visualization', '1', {'packages':['table']});
>
>   // Set a callback to run when the API is loaded.
>   google.setOnLoadCallback(init);
>
>   // Send the query to the data source.
>   function init() {
>
>     // Specify the data source URL.
>     var query = new google.visualization.Query('Beat');// name of my
> servlet
>
>     // Send the query with a callback function.
>     query.send(handleQueryResponse);
>   }
>
>   // Handle the query response.
>   function handleQueryResponse(response) {
>     if (response.isError()) {
>       alert('Error in query: ' + response.getMessage() + ' ' +
> response.getDetailedMessage());
>       return;
>     }
>
>     // Draw the visualization.
>     var data = response.getDataTable();
>     var chart = new
> google.visualization.Table(document.getElementById('chart_div'));
>     chart.draw(data, {width: 600, height: 150, is3D: true});
>   }
>   </script>
> </head>
> <body>
>   <h1>Hello! Data Source!</h1>
>
>   A table chart that shows data taken from the simple data source.
>   <!--Div that will hold the visualization-->
>   <div id="chart_div"></div>
> </body>
> </html>
>
> And I get perfect chart.
>
> Now I want to design such that when the user hits the address to the
> servlet I dont want  the following result
> ............................................}]},{c:[{v:'Tiger'},
> {v:'http://en.wikipedia.org/wiki/Tiger'},{v:80.0},{v:false}]} which is
> ok
>
> instead i want to draw the chart directly using the the above html
> page.
> I tried using dispactcher.forward(XXX.html);
> but i am getting error.
>
> So i got hint from the 
> site....http://code.google.com/apis/visualization/documentation/dev/dsl_key_c...
> Has anyone tried this or what should be the approach to process and
> draw the chart on one hit and just showing the chart on user's
> browser?
>
> On Jun 10, 10:18 am, Badtnik <[email protected]> wrote:
>
> > Hey, can you send a simple code snippet causing that response and we
> > can help you debug it?
>
> > On Jun 10, 5:11 pm, Akku <[email protected]> wrote:
>
> > > I am following this 
> > > tutorialshttp://code.google.com/apis/visualization/documentation/dev/dsl_csv.html
>
> > > It works fine for  me but i am facing one problem
>
> > > at the following step given by google
> > > Updating Your Web Application on Apache Tomcat
> > > Click the following 
> > > link:http://localhost:8080/myWebApp/csv?url=http://localhost:8080/myWebApp...
>
> > > The screen displays 6-7 lines of text, depending on your screen width.
> > > The text begins with google.visualization.Query.setResponse
> > > and ends with {c:[{v:'Bob'},{v:'Jane'}]}]}});
>
> > > This is the response that the example CSV data source sends to a
> > > visualization.
>
> > > I DONT want this thing coming in my browser
> > > instead i want to directly draw the chart  after user hit the link
> > > as given by google
> > > Using a Visualization to View the Data
> > > The all_examples.html file in the <data_source_library_install>/
> > > examples/src/html directory can be used to view a visualization of the
> > > data.
>
> > > what can i do to follow all the step and directly draw the chart ?
> > > thanking you in advance

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-visualization-api?hl=en.

Reply via email to