Can't display the chart in jsp

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Abraham Daniel
Posts: 2
Joined: Mon Aug 18, 2003 9:36 pm

Can't display the chart in jsp

Post by Abraham Daniel » Mon Aug 18, 2003 11:35 pm

Hi, I am a new user, i started using jfree from last week, i have been using jfreechart to output the results in a graphical format. I am trying to retrieve the output data from the SQL database and i am using the JDBCXYDataset for it. Here is the java code
JDBCXYDataset data = null;
try
{
data = new JDBCXYDataset(connect);
String sql1 = "SELECT year,somtc,totc FROM NebraskaRunsTemp WHERE surftext = '" + surftext + "' AND base = '" + base + "' AND recent = '" + recent + "' AND hydric = '" + hydric + "' AND method1 = '" + method1 + "' AND method2 = '" + method2 + "' AND rotation1 = '" + rotation1 + "' AND rotation2 = '" + rotation2 + "'";
data.executeQuery(sql1);
JFreeChart chart = ChartFactory.createTimeSeriesChart("Sample XY Chart","Year","Somtc",data1,true,true,false);
response.setContentType("image/png");
ChartUtilities.writeChartAsPNG(out, chart, 400, 300);
}

I get this following error

C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\coreservlets\ViewResults_jsp.java:193: cannot resolve symbol
symbol : method writeChartAsPNG (javax.servlet.jsp.JspWriter,org.jfree.chart.JFreeChart,int,int)
location: class org.jfree.chart.ChartUtilities
ChartUtilities.writeChartAsPNG(out, chart, 400, 300);

I don't know what i am doing wrong here. Any help will be appreciated.

Thanks

rfuller
Posts: 8
Joined: Tue Aug 19, 2003 2:34 pm
Location: Galway, Ireland

Post by rfuller » Tue Aug 19, 2003 3:03 pm

//try
ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 400, 300);

//rather than
//ChartUtilities.writeChartAsPNG(out, chart, 400, 300);

alskor
Posts: 2
Joined: Thu Aug 21, 2003 9:40 am
Contact:

text - image - text again

Post by alskor » Thu Aug 21, 2003 9:45 am

rfuller wrote://try
ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 400, 300);

//rather than
//ChartUtilities.writeChartAsPNG(out, chart, 400, 300);
if I write some text in my jsp, then use code like this (see below), then write some text again, then I receive "text - garbage - text" on my html page.
maybe I need to use response.setContentType("image/png") another way here? the garbage starts with symbols "‰PNG ", so it looks like a valid PNG file, this should be printed as an image, not just typed as a text.

Code: Select all

<%
    JFreeChart chart = (JFreeChart) request.getAttribute("my_chart_blin");
    response.setContentType("image/png");
    ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 600, 300);
%>

alskor
Posts: 2
Joined: Thu Aug 21, 2003 9:40 am
Contact:

another way

Post by alskor » Thu Aug 21, 2003 10:09 am

maybe it is possible to perform the page include - like

... JSP here ...

page include - get the jpeg image with content type image/jpeg

... text from jsp again...

Bryan.Scott
Posts: 26
Joined: Fri May 09, 2003 4:55 am
Location: Tasmania, Australia
Contact:

Cewolf Project

Post by Bryan.Scott » Thu Aug 21, 2003 10:29 am

Hi

Just a note to let you know that the cewolf project (a jsp tag library for jfreechart) will be adding support for the jdbcDatasets soon.

I do not have direct cvs access but first version of the code has been submitted to the project administrator and I am about to submit the first patch to the code.

Bryan
Bryan

Locked