Creating and exporting chart to jpg at server side

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
SDG
Newbie
Newbie
Posts: 40
Joined: Tue Apr 08, 2003 4:00 am

Creating and exporting chart to jpg at server side

Post by SDG » Mon Jun 15, 2009 11:20 am

Hello,

I am trying to create chart class, exporting it to jpg and display at browser as JRE is not allowed to install at browser's system. But I am getting error while creating class itself. Please find the code and error message below.

source:
---------------------------
CreateGraph.java
---------------------
public class CreateGraph extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

public void init(ServletConfig config) throws ServletException{
super.init(config);
System.out.println(config.getServletName());
System.out.println(config.getInitParameterNames());
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
String var0show = "";
try
{
var0show = request.getParameter("showthis");
}
catch(Exception e)
{
e.printStackTrace();
}
MyChart mychart = new MyChart();

response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Create Graph</title></head>");
out.println("<body>");
out.println("<p>Create Graph</p>");
out.println("</body></html>");

out.close();
}
}

MyChart.java
------------------------------
public class MyChart extends ChartPanel {
//public class MyChart extends SamplePanel {
private static long icurrentTimeMillis;
private static DateTime PrepareDateTime(){
if (icurrentTimeMillis == 0) {
icurrentTimeMillis = System.currentTimeMillis();
}
icurrentTimeMillis = icurrentTimeMillis + 1000;
return new DateTime(System.currentTimeMillis() + icurrentTimeMillis);
}

public MyChart() {
Line series1;
series1 = new Line(chart1.getChart());
series1.setColorEach(false);
series1.getMarks().setArrowLength(20);
series1.getMarks().setVisible(false);
series1.setDark3D(false);
try {
DateFormat formatter = new SimpleDateFormat("SSS");
long cTM = System.currentTimeMillis() + 9 * 60 * 60 * 1000;
Random random = new Random(1000);
for (int iIndex = 0; iIndex < 1000; iIndex++) {
Date date = formatter.parse(String.valueOf(cTM));
cTM = cTM + 1000;
//System.out.println(date + " " + date.getTime());
Timestamp st = new Timestamp(cTM);
java.sql.Timestamp timeStampDate = new Timestamp(date.getTime());
//System.out.println(st.getTime() + " " + timeStampDate.getTime());
DateTime dt = new DateTime(cTM);
series1.add(dt, random.nextInt());

}
} catch (Exception e) {
System.out.println(e);
}

chart1.getAxes().getBottom().getLabels().setAngle(90);
chart1.getAxes().getBottom().getLabels().setDateTimeFormat("hh:mm:ss.SSS");
this.setBackground(Color.YELLOW);
validate();
repaint();
}


}

Error is:
---------------
java.lang.NoClassDefFoundError: com/steema/teechart/IBaseChart
at CreateGraph.doGet(CreateGraph.java:25)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)


Thanks in advance,
Best,
Veeranna Ronad.

Marc
Site Admin
Site Admin
Posts: 1213
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Creating and exporting chart to jpg at server side

Post by Marc » Tue Jun 16, 2009 7:34 am

Hello Veeranna,

There's no apparent problem with the code though I don't see how the imports are setup. Please check that you have imports linked to your Chart classes. You could add a direct import to com.steema.teechart.IBaseChart.

Regards,
Marc Meumann
Steema Support

SDG
Newbie
Newbie
Posts: 40
Joined: Tue Apr 08, 2003 4:00 am

Re: Creating and exporting chart to jpg at server side

Post by SDG » Tue Jun 16, 2009 10:14 am

Dear Marc,

I added import com.steema.teechart.IBaseChart; to CreateGraph.java source. Even after this I get error. Please find the attached source.

Error;
--------
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet execution threw an exception
root cause
java.lang.NoClassDefFoundError: com/steema/teechart/IBaseChart
com.CreateGraph.doGet(CreateGraph.java:27)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.14

Kindly advice me.

Thanks in advance,
Best,
Veeranna Ronad.
Attachments
src.7z
Project where TeeChart instance is created.
(7.95 KiB) Downloaded 982 times

Marc
Site Admin
Site Admin
Posts: 1213
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Creating and exporting chart to jpg at server side

Post by Marc » Thu Jun 18, 2009 3:04 pm

Hello Veeranna,

To check your example, I took your code units and added them to a new web project in Netbeans. To simplify any possible pathing problems I put the units from the MyServlet folder in the same folder as the CreateGraph.java file and removed all 'package xxxx' lines from the beginning of each unit. I added the call to CreateGraph to the project's servlet list.

A library path to TeeChart.Swing.jar was added to the project library path.

To check that the CreateGraph is correctly interacting with TeeChart itself I modded a couple of the lines in CreateGraph to read then modify the Chart header.

Code: Select all

MyChart mychart = new MyChart();

response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Create Graph</title></head>");
out.println("<body>");
out.println("<p>Create Graph</p>");

//test lines
out.println("<p>Old Header: "+mychart.chart1.getChart().getHeader().getText()+"</p>");
mychart.chart1.getChart().getHeader().setText("My test TeeChart header");
out.println("<p>New Header: "+mychart.chart1.getChart().getHeader().getText()+"</p>");

out.println("</body></html>");
out.close();
The project was deployed from the IDE and ran successfully.

Please check your setup against these steps. If they don't clarify any possible causes of the problem in your installation then we'll need to compare details of project setup, etc.

Regards,
Marc
Steema Support

Post Reply