Its giving me this error java.lang.ClassCastException: com.google.visualization.datasource.datatable.DataTable cannot be cast to com.google.visualization.datasource.DataTableGenerator
On Jun 10, 5:41 pm, Akku <[email protected]> wrote: > I found that the error is in > DataSourceHelper.executeDataSourceServletFlow(request, response, > (DataTableGenerator) data, isRestrictedAccessMode()); line > its not going in the next line. > Cant any one please suggest why is this happening. > Actually I was to make this > linkhttp://code.google.com/apis/visualization/documentation/dev/dsl_get_s... > as a single event and the chart should be draw.... is ther any easy > method.... or what I am doing is right? > Why is this code not running after that line. > Please suggest guys I am badly struggling :( > > @Override > protected void doGet(HttpServletRequest request, > HttpServletResponse response) > throws ServletException, IOException { > response.setContentType("text/html;charset=UTF-8"); > PrintWriter out = response.getWriter(); > // processRequest(request, response); > try{ > System.out.println("##1"); > DataTable data = generateDataTable(null, request); > System.out.println("##2"); > DataSourceHelper.executeDataSourceServletFlow(request, response, > (DataTableGenerator) data, isRestrictedAccessMode());<<<<<<- i think > some problem here > > /////then i want to do is > // RequestDispatcher rd; > //rd = request.getRequestDispatcher("newhtml.html"); > //rd.include(request, response);//forward(request, response); // i > hope this will work fine > > System.out.println("##3"); > out.println("<html>"); > out.println("<head>"); > out.println("<title>Servlet Test2</title>"); > out.println("</head>"); > out.println("<body>"); > out.println("<h1>Servlet Test2 at " + > request.getContextPath () + "</h1>"); > out.println("</body>"); > out.println("</html>"); > > } > finally { > out.close(); > } > > } > > @Override > public Capabilities getCapabilities() { > return Capabilities.NONE; > } > > protected boolean isRestrictedAccessMode() { > return false; > } > > �...@override > 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/ > Aksahy adgasidge", 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; > } > > On Jun 10, 3:53 pm, Akku <[email protected]> wrote: > > > how can i make this entire process as 1 single > > event???http://code.google.com/apis/visualization/documentation/dev/dsl_get_s... > > and draw the chart on single click? > > > On Jun 10, 3:08 pm, Akku <[email protected]> wrote: > > > > 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. > > ... > > read more » -- 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.
