Java Chart Designer API : Method getImage() from class ELChart crashes (solved)(Read 8958 times)
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: javascript:void(0);
   
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
« Last Edit: August 07, 2012, 03:37:47 PM by jasper »



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.



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: javascript:void(0);
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



 

Sitemap 1 2 3 4 5