Sikander - 2006-09-13

Hi All,

I'm using cewolf example to make some graphs.
Everithing is fine but my chart appears empty (I have the image graph with no data, in fact i have values on y axis and none on x axis).

My code is:

package de.laures.cewolf.example;
import java.lang.*;
import java.sql.*;
import java.io.*;
import java.util.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.io.Serializable;
import javax.sql.*;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import de.laures.cewolf.DatasetProduceException;
import de.laures.cewolf.DatasetProducer;
import de.laures.cewolf.links.CategoryItemLinkGenerator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jfree.chart.entity.CategoryItemEntity;
import de.laures.cewolf.tooltips.CategoryToolTipGenerator;

public class GraficoPerformance implements DatasetProducer, Serializable {

    private static final Log log = LogFactory.getLog(GraficoPerformance.class);

    private static final String sIpServidor = "xx.xx.xxx.xx";
        private static final String sPort = "xxxx";
        private static final String sDataBase = "fmsdb";
        private static final String sUserName = "xxxxxx";
        private static final String sPassword = "xxxxxx";
        private static final String sURL = "jdbc:oracle:thin:@" + sIpServidor + ":" + sPort + ":" + sDataBase;

    public Object produceDataset(Map params) throws DatasetProduceException {
    
     // Criando um Dataset para o gráfico de linhas
     log.debug("producing data.");
       
        DefaultCategoryDataset dataset = new DefaultCategoryDataset(){

   protected void finalize() throws Throwable {
    super.finalize();
    log.debug(this +" finalized.");
   }
        };
       
        /**
        * Executando a Query e obtendo o data set sobre o resultado
        */
        PreparedStatement ps = null;
        ResultSet rs = null;      
       
        if(params.containsKey("range"))
        {
        String range = (String)params.get("range");              
               }
        if (params.containsKey("id_maquina"))
               {
        String id_maquina = (String)params.get("id_maquina");              
               }
        if (params.containsKey("keep_alive"))
               {
        String keep_alive = (String)params.get("keep_alive");                             
               }
                 
        String query = "select ((data_hora_gravacao - to_date(data_ocorrencia||''||hora_ocorrencia||''||min_ocorrencia,'dd/mm/yyyy hh24:mi:ss'))*86400), mnemonico_alarme, to_char(data_hora_gravacao,'hh24:mi:ss') from sgf_sica_old where data_hora_gravacao < SYSDATE and data_hora_gravacao > (SYSDATE - 1/24) and mnemonico_alarme like '" + params.get("id_maquina") + "%' and mnemonico_alarme like '%"  + params.get("keep_alive") + "' order by data_hora_gravacao desc";
        try {
        
                  Connection conexao = null;
                  // get a connection from the database        
                  try {
                      Class.forName("oracle.jdbc.driver.OracleDriver");
                      System.out.println("loading oracle driver...!");
                      conexao = DriverManager.getConnection(sURL, sUserName, sPassword);
                      System.out.println("made connection to fmsadm!");
                      } catch (Exception ex) {
                      ex.printStackTrace(); 
                      conexao = null;
                      }
                  return conexao;      
       
                  ps = conexao.prepareStatement(query);
                  rs = ps.executeQuery();
                            
                  while (rs.next())
                  {          
                  // Inserindo no DataSet a data_hora_gravacao e o tempo de processamento.
                     dataset.addValue(rs.getInt(1), rs.getString(2), rs.getString(3));
                  }
             }           
             catch (SQLException e) {
             log.debug(e);
             }
                     
       return dataset;
    }

 
public boolean hasExpired(Map params, Date since) { 
        log.debug(getClass().getName() + "hasExpired()");
  return (System.currentTimeMillis() - since.getTime())  > 5000;
}

public String getProducerId() {
  return "Performance";
}
}

My jsp code try to make a line graph..

This code make a chart like this:
    
     ^
1.050|
...  |
0.325|
0.300|
0.275|
0.250|
0.225|
0.200|
0.175|
0.150|
0.125|
0.100|
0.075|
0.050|
0.025|
0.000|_________________________________________>
                  Horario de Saida
                   
On Y axis, the values from database are like 25, 250, 1500 and not like the graphs show with (0.)before number.
On X axis i will have a number like 12-09-06

Perhaps, should i use the
<cewolf:chart    
id="XYChart"   
type="xy"   
...

Can you help me.... I'm really need to make it works...