Creating and exporting chart to jpg at server side
Posted: 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.
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.