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 :

Dynamic line chart update


Sujet :

2D Java

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 30
    Par défaut Dynamic line chart update
    hello ,

    j'ai un problème d'instance :

    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
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
     
        package com.sauter_controls.jbacnet.chart;
     
        import java.awt.*;
        import java.awt.event.ActionEvent;
        import java.awt.event.ActionListener;
        import java.io.PrintStream;
        import javax.swing.*;
     
        import org.jfree.chart.*;
        import org.jfree.chart.axis.*;
        import org.jfree.chart.plot.CombinedDomainXYPlot;
        import org.jfree.chart.plot.XYPlot;
        import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
        import org.jfree.chart.title.LegendTitle;
        import org.jfree.data.time.*;
        import org.jfree.ui.*;
        import org.jfree.util.UnitType;
     
     
     
        public class DynamicWithLignes extends ApplicationFrame
        {
           public static JButton jbutton;
           public static double val_pv;
     
     
           static class MyDemoPanel extends MyPanel implements ActionListener   
           {
     
              public void actionPerformed(ActionEvent actionevent)
                {
     
                    if(actionevent.getActionCommand().equals("ADD_ALL"))
                    {
                        Millisecond millisecond = new Millisecond();
                        System.out.println("Now button= " + millisecond.toString()+"\n Valeur Pv= "+val_pv);
                        timeseries.add(new Millisecond(),val_pv);
     
     
                    }
                }
     
              //public static final int SUBPLOT_COUNT = 1;
              private static TimeSeriesCollection datasets;
              //private double pv;
              private TimeSeries timeseries;
     
     
     
              public static TimeSeriesCollection getDatasets() {
                 return datasets;
              }
              public static void setDatasets(TimeSeriesCollection datasets) {
                 MyDemoPanel.datasets = datasets;
              }
              public TimeSeries getTimeseries() {
                 return timeseries;
              }
              public void setTimeseries(TimeSeries timeseries) {
                 this.timeseries = timeseries;
              }
              public MyDemoPanel( )
              {
                 super(new BorderLayout());
     
                 CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new DateAxis("Time"));
                 //datasets = new TimeSeriesCollection();
     
                 //pv = 0D;
                 timeseries = new TimeSeries("pv");
                 datasets = new TimeSeriesCollection(timeseries);
                 NumberAxis numberaxis = new NumberAxis("Present value");
                 numberaxis.setAutoRangeIncludesZero(false);
                 XYPlot xyplot = new XYPlot(datasets, null, numberaxis, new StandardXYItemRenderer());
                 xyplot.setBackgroundPaint(Color.lightGray);
                 xyplot.setDomainGridlinePaint(Color.white);
                 xyplot.setRangeGridlinePaint(Color.white);
                 combineddomainxyplot.add(xyplot);
     
     
                 JFreeChart jfreechart = new JFreeChart("Present Values ", combineddomainxyplot);
                 addChart(jfreechart);
                 LegendTitle legendtitle = (LegendTitle)jfreechart.getSubtitle(0);
                 legendtitle.setPosition(RectangleEdge.BOTTOM);
                 legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D));
                 jfreechart.setBorderPaint(Color.black);
                 jfreechart.setBorderVisible(true);
                 ValueAxis valueaxis = combineddomainxyplot.getDomainAxis();
                 valueaxis.setAutoRange(true);
                 valueaxis.setFixedAutoRange(20000D);
                 ChartUtilities.applyCurrentTheme(jfreechart);
                 ChartPanel chartpanel = new ChartPanel(jfreechart);
                 add(chartpanel);
                 JPanel jpanel = new JPanel(new FlowLayout());
     
                    jbutton = new JButton("ALL");
                    jbutton.setActionCommand("ADD_ALL");
                    jbutton.addActionListener(this);
                    jpanel.add(jbutton);
                    add(jpanel, "South");
     
     
     
                 chartpanel.setPreferredSize(new Dimension(500, 270));
                 chartpanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
     
     
     
              }
              public void update(double pv) {
                 Millisecond millisecond = new Millisecond();
                 val_pv = pv;
                   //datasets.getSeries(0).add(new Millisecond(), pv);
                   //timeseries.add(new Millisecond(),pv);
                   //datasets.addSeries(timeseries);
                   System.out.println("Now update= " + millisecond.toString());
     
              }
     
     
     
           }
     
           private static MyDemoPanel pane ;
     
           public DynamicWithLignes(String s)
           {
              super(s);
              setContentPane(createDemoPanel());
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           }
     
           public static JPanel createDemoPanel()
           {
              pane=new MyDemoPanel();
              return pane;
           }
     
           public static void main(String args[])
           {
              DynamicWithLignes dynamic = new DynamicWithLignes("Present values");
              dynamic.pack();
              RefineryUtilities.centerFrameOnScreen(dynamic);
              dynamic.setVisible(true);
           }
     
           public static void upChart(double pv) {
              //pane.getTimeseries().add(new Millisecond(),pv);
              //System.out.println("passe dans upChart");
              pane.update(pv);
              jbutton.doClick();
              //pane.revalidate();
              //pane.repaint();
           }
     
        }
    pour ajouter une nouvelle valeur:
    (dans un autre fichier)
    DynamicWithLignes.upChart(Double.parseDouble(pv));

    Pour afficher le graph:
    (encore dans un autre fichier)
    add(DynamicWithLignes.createDemoPanel(), BorderLayout.CENTER);


    J'ai ajouté un bouton pour voir si il est cliqué quand j'ajoute une valeur
    j'ai plusieurs onglets en swing et le graph s'affiche dans le mauvais onglet
    c'est donc un problème d'instance mais je sais pas comment faire pour récupérer la bonne instance. Existe - il un pattern qui fait cela ? Je ne peut pas faire de singleton vu que j'ai plusieurs onglets qui affiche la même chose mais le contenu doit être différent.

    The dataset and timeseries are correctely fulled.

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 30
    Par défaut
    Qui sait comment on récupère l'instance d'un panel qui est dans un autre panel et dans une autre classe ?

Discussions similaires

  1. discontinuité des courbes dans un line chart dans jsp
    Par naruto_informaticien dans le forum Servlets/JSP
    Réponses: 0
    Dernier message: 12/02/2010, 17h32
  2. [Line Chart] Les lignes ne s'affichent pas
    Par padhalur dans le forum iReport
    Réponses: 3
    Dernier message: 04/12/2008, 11h31
  3. [JFreeChart] Line Chart Multi Axes
    Par wiss20000 dans le forum 2D
    Réponses: 7
    Dernier message: 23/05/2007, 15h56
  4. Line Chart vide
    Par LaNat dans le forum iReport
    Réponses: 5
    Dernier message: 08/11/2006, 13h59

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