Forum - Info Center - Eltima Software

Eltima Help Center => The rest of our products & other questions => Topic started by: jasper on August 06, 2012, 05:05:16 PM

Title: Java Chart Designer API : Method getImage() from class ELChart crashes (solved)
Post by: jasper on August 06, 2012, 05:05:16 PM
Hello forum,
I'm new with the Java Chart Designer and I ask myself what I have done..
Here my problem:
I want to create a Java Servlet which builds a chart as gif. So I have
integrated the packages eltima-chart.jar and eltima-chartDesigner.jar into
my IDE JBuilder 2008R2. As second step I integrated the chart-demo
into a new Java Servlet. The compilation works fine, but if I call the method
getImage(), the application crashed :(.

Here is the short code:
Code: [Select]
   
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
   Image img;
   response.setContentType(CONTENT_TYPE);
   ELChart chart = new ELChart();
   ELChartDataModel dataModel;
   String[] series     = new String[] {"Orange", "Apple", "Banana"};
   String[] categories = new String[] {"Jan", "Feb", "Mar", "Apr"};

   java.lang.Number[][] data = new Number[][]
   {
      {new Integer(12), new Integer(14), new Integer(3)},
      {new Integer(14), new Integer(16), new Integer(8)},
      {new Integer(16), new Integer(19), new Integer(13)},
      {new Integer(18), new Integer(23), new Integer(14)}
   };

   dataModel = new ELChartDataModel( series, categories, data );

   chart.setELChartDataModel(dataModel);
   chart.setType(ELChart.TYPE_COLUMN);
   chart.setSubType(1);
   chart.getHeaderPanel().getTitle().setText("Fruit production");
   chart.getHeaderPanel().getSubTitleLabel().setText(null);
   chart.getFooterPanel().getTextLabel().setText("ELChart demo");
   chart.animationStart();
   img = chart.getImage(1041,537,100); // here crashes the application
   chart.animationStop();
   OutputStream output = response.getOutputStream();
   GifEncoder encode = new GifEncoder(img,output);
   encode.encode();
   
}

..is here anybody who can tell me what is wrong?
I guess that I forgot something, but what? :-\

Regard

Jasper
Title: Re: Java Chart Designer API : Method getImage() from class ELChart crashes
Post by: James Foster on August 07, 2012, 10:59:00 AM
Hello Jasper,

I have passed the report about issue to our testers team. They are investigating the reason of the crash. I will get back to you as soon as I receive their answer. Thank you for your patience.
Title: Re: Java Chart Designer API : Method getImage() from class ELChart crashes
Post by: jasper on August 07, 2012, 03:31:07 PM
Hello James,
now near at the end of my working day i have found the reason of my problem:
I misunderstood the parameter scale in the method getImage().My value 100
was complete nonsens :).
Here is my executable code:
Code: [Select]
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
   Image img = null;

   response.setContentType(CONTENT_TYPE);//image/jpeg
   ELChart chart = new ELChart();
   ELChartDataModel dataModel;
   String[] series     = new String[] {"Orange", "Apple", "Banana"};
   String[] categories = new String[] {"Jan", "Feb", "Mar", "Apr"};
   java.lang.Number[][] data = new Number[][]
   {
      {new Integer(12), new Integer(14), new Integer(3)},
      {new Integer(14), new Integer(16), new Integer(8)},
      {new Integer(16), new Integer(19), new Integer(13)},
      {new Integer(18), new Integer(23), new Integer(14)}
   };
   dataModel = new ELChartDataModel( series, categories, data );
   chart.setELChartDataModel(dataModel);
   chart.setType(ELChart.TYPE_COLUMN);
   chart.setSubType(1);
   chart.getHeaderPanel().getTitle().setText("Bananas for all Developers");
   chart.getHeaderPanel().getSubTitleLabel().setText("Hallo");
   chart.getFooterPanel().getTextLabel().setText("ELChart demo");
   chart.animationStart();
   chart.animationStop();
   chart.setBounds(0, 0, 1041, 537);
   img = chart.getImage(1041,537,1);
   BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null),BufferedImage.TYPE_INT_RGB);
   Graphics g = bi.createGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
 
   //ImageIO.write(bi,"jpg",new File("C:\\temp\\elchart.jpg"));
   
   OutputStream output = response.getOutputStream();
   ImageIO.write(bi, "jpg", output);
}

Some insights just takes a little longer..

Regard

Jasper