IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

2D Java Discussion :

[JFreeChart] Erreur "org.jfree.data.general.SeriesException: You are attempting to.."


Sujet :

2D Java

  1. #1
    Membre averti Avatar de mouss4rs
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    884
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 884
    Points : 355
    Points
    355
    Par défaut [JFreeChart] Erreur "org.jfree.data.general.SeriesException: You are attempting to.."
    Bonjour,

    J'essaye de générer un graphique dans mon interface Swing qui prend comme donnée, l'heure, le jour, le mois et l'année ainsi que la mesure d'un patient que j'extrais de la BDD pour les mettre en arguments dans ma méthode addData():
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    public class GraphiquePatient extends JPanel{
     
        private int idmesure=1;
        private int day=20;
        private int month=5; 
        private int year=2008;
        private double mesure=1.80;
        NumberAxis rangeAxis;
     
        ChartPanel chartPanel;
        JFreeChart chart;
     
        TimeSeries ligne_patient= null;
     
        RegularTimePeriod rtp;
     
        TimeSeriesCollection dataSet = new TimeSeriesCollection();
     
        public GraphiquePatient(){
     
            JPanel p = new JPanel();
     
        // Couleurs des lignes
            Color COULEURLIGNE1 = Color.black;
     
        // On ajoute les lignes dans le dataset
     
        // Creation des lignes
            ligne_patient = new TimeSeries("Patient 1", Hour.class);
     
        // Ajout des ligne dans le dataset
            dataSet.addSeries(ligne_patient); 
     
        // Creation du graphique
            chart = ChartFactory.createTimeSeriesChart("Evolution du Taux de glycémie du patient","Période","Taux de glycémie",dataSet,true,false,false);
     
            chartPanel = new ChartPanel(chart, true);
     
        // Les dimensions du graphique
            Dimension d = new Dimension(350,250);
     
            chartPanel.setMaximumSize(d); 
            chartPanel.setPreferredSize(d); 
            chartPanel.setMinimumSize(d);
     
            p.add(chartPanel);
     
            XYPlot plot = (XYPlot) chart.getPlot(); 
     
        // On definie une couleur pour les lignes
            plot.getRenderer().setSeriesPaint(0,COULEURLIGNE1); 
     
        // On definie une couleur de fond pour le graphique
            plot.setBackgroundPaint(Color.white);
     
            rangeAxis = (NumberAxis) plot.getRangeAxis();
     
        // On fixe une taille pour l'axe des ordonnées
            rangeAxis.setUpperBound(5.0);
     
            add(p);
     
            addData(idmesure, day, month, year, mesure);
     
            this.setVisible(true);
        }
        // On ajoute des données
        public void addData(int idmesure, int day, int month, int year, double mesure){    
     
            ligne_patient.setNotify(true);
     
            ligne_patient.addOrUpdate(new Hour(idmesure,day,month,year), mesure);
            dataSet.addSeries(ligne_patient);
     
            // Titre du graphique
            ligne_patient.fireSeriesChanged();
            chartPanel.setChart(chart);    
        }
    qui permet d'ajouter les donnée au graphique par la méthode voirGraphique() de la classe ADO comme voici:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    public void voirGraphique(Fenetre fen){
            try {
                boolean drapeau = false;
                int nblignes= fen.getTm().getRowCount();
                
                Statement stmt = connection.createStatement();
                ResultSet rs = stmt.executeQuery("SELECT mesure.* FROM mesure, patient WHERE id_patient=ref");
                while (rs.next()) {
                    if (rs.getObject(8).equals(refSuivi)){
                        drapeau = true;
                        int idmesure =(Integer)rs.getObject(1);
                        System.out.println("numéro mesure: "+idmesure);
                        
                        date=(String) rs.getObject(4);
                        heure=(String) rs.getObject(6);
                        glycemie=(Double) rs.getObject(5);
                        axtrapide=(Double) rs.getObject(2);
                        mixtard30=(Double) rs.getObject(7);
                        commentaire=(String) rs.getObject(3);
                        
                        int hour= Integer.parseInt(heure.substring(0,2));
                        System.out.println("heur: "+hour);
                        int day = Integer.parseInt(date.substring(0,2));
                        System.out.println("dat: "+day);
                        int month = Integer.parseInt(date.substring(3,5));
                        System.out.println("mois: "+month);
                        int year = Integer.parseInt(date.substring(6,10));
                        System.out.println("annee: "+year);
                        System.out.println("mesure: "+glycemie);
                        
                        gp.addData(idmesure, day, month, year, glycemie);                }
              }
              if(drapeau==false){
                    Toolkit.getDefaultToolkit().beep();
                    JOptionPane.showMessageDialog(fen,
                            "aucune mesure pour le patient", "Information",
                            JOptionPane.INFORMATION_MESSAGE);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    Donc normalement lorsque je renseigne le code du patient dans l'interface, cette méthode doit me générer dynamiquement l'évolution du taux de glycémie.
    Or je me retrouve avec cette erreur ci a chaque fois:
    Exception in thread "AWT-EventQueue-0" org.jfree.data.general.SeriesException: You are attempting to add an observation for the time period Mon May 05 02:00:00 CEST 2008 but the series already contains an observation for that time period. Duplicates are not permitted. Try using the addOrUpdate() method. at org.jfree.data.time.TimeSeries.add(TimeSeries.java:527)
    at org.jfree.data.time.TimeSeries.add(TimeSeries.java:570)
    at org.jfree.data.time.TimeSeries.add(TimeSeries.java:556)
    at modeles.GraphiquePatient.addData(GraphiquePatient.java:101)
    at ado.ADO.voirGraphique(ADO.java:253)
    at modeles.Fenetre.actionPerformed(Fenetre.java:420)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    J'ai bien mis la méthode addOrUpdate() à la place de .add() mais toujours la même erreur.

    De même que, l'axe des abscisses est gradué d'une manière très bizarre.

    Si quelqu'un a une idée du problème ?

    Merci d'avance pour votre aide.

  2. #2
    Membre averti Avatar de mouss4rs
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    884
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 884
    Points : 355
    Points
    355
    Par défaut
    La solution est d'utiliser la méthode repaint().

  3. #3
    Candidat au Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Février 2012
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Février 2012
    Messages : 2
    Points : 3
    Points
    3
    Par défaut
    j'ai un probleme similaire, moi je souhaiterais tracer les courbes journalières à l'échelle des minutes. J'arrive à récupérer les données en base mais j'obtiens
    Exception in thread "main" org.jfree.data.general.SeriesException: You are attempting to add an observation for the time period Mon Feb 13 08:46:00 WAT 2012 but the series already contains an observation for that time period. Duplicates are not permitted. Try using the addOrUpdate() method.
    at org.jfree.data.time.TimeSeries.add(TimeSeries.java:611)
    at org.jfree.data.time.TimeSeries.add(TimeSeries.java:656)
    at org.jfree.data.time.TimeSeries.add(TimeSeries.java:642)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 20/01/2014, 10h26
  2. Réponses: 2
    Dernier message: 15/01/2007, 14h42
  3. erreur dans la connection data environement
    Par halhali07 dans le forum VB 6 et antérieur
    Réponses: 7
    Dernier message: 30/06/2006, 18h55
  4. [SQL] Erreur grand débutant echo / $data
    Par carelha dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 15/05/2006, 12h01
  5. [JDBC] [Oracle] Erreur : End of TNS data channel
    Par loicmillion dans le forum JDBC
    Réponses: 2
    Dernier message: 01/02/2005, 14h27

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo