Make charts appear in new broswer

Discussion about JFreeChart related to stockmarket charts.
Locked
Souma
Posts: 17
Joined: Sun Nov 20, 2005 4:02 am

Make charts appear in new broswer

Post by Souma » Wed Nov 30, 2005 4:27 am

This is how my demo works, i have a button in my jsp page (AvailableChart.jsp). So when i click a button (Show me BarChart), it post to the BarChart servlet which is called ChartTest. Instead of displaying the chart on the same page on AvailableChart.jsp i want it to be shown on a new browser, a pop up window (DisplayChart.jsp). So how am i going to do that with my current codes.

Codes for AvailableChart.jsp

Code: Select all

<form action="ChartTest" method="post"> 
&nbsp;Pie Chart&nbsp<input type="submit" value="View"/> 
</form>
Codes for my servlet, ChartTest.java (*this codes currently display chart on existing page of AvailableChart.jsp which i don't want it to)

Code: Select all

package Servlet;

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;

import org.jfree.chart.ChartFactory; 
import org.jfree.chart.ChartUtilities; 
import org.jfree.chart.JFreeChart; 
import org.jfree.data.general.DefaultPieDataset; 

public class ChartTest extends HttpServlet {
    
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
    
        String[][] aryDat = {{"a","150000"}, {"b","55500"}, {"c","75000"}, {"d","83100"}, {"e","22500"}}; 

        DefaultPieDataset objDpd = new DefaultPieDataset(); 

        for(int i = 0; i < aryDat.length; i++){ 
            objDpd.setValue(aryDat[i][0],Integer.parseInt(aryDat[i][1])); 
        } 

        JFreeChart objCht = ChartFactory.createPieChart3D("My Chart", objDpd, true, false, false); 

        response.setContentType("text/html");
        ServletOutputStream objSos = response.getOutputStream(); 
        ChartUtilities.writeChartAsJPEG(objSos, objCht, 600, 400);
    } 
}
Main point:
1) I don't know what to modify to my servlet codes to be able to display my chart to DisplayChat.jsp
2) I don't know what to code for my jsp page(DisplayChart.jsp) in order to display the chart i've created.

I really need help please, many thanks. Good day to all.

Regards.

Guest

pxs

Post by Guest » Thu Jan 12, 2006 10:10 pm

Hi. Try this:

Form in AvailableChart.jsp >

Code: Select all

<form action="DisplayChart.jsp" method="post" target="_blank">
 Pie Chart
 <input type="submit" value="View"/>
</form> 
and the DisplayChart.jsp code like this>

Code: Select all

...
...
<img src="DisplayChart" alt="MyCoolChart">
...
...
Enjoy.

Locked