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

 Java Discussion :

Créer un graphique glissant


Sujet :

Java

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2019
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Nièvre (Bourgogne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Transports

    Informations forums :
    Inscription : Octobre 2019
    Messages : 4
    Points : 5
    Points
    5
    Par défaut Créer un graphique glissant
    Bonsoir à toutes et à tous,

    J'ai un tableau de 400 valeur, que j'actualise toutes les 100ms en "décalant vers la gauche" et en ajoutant une valeur dans la dernière case.
    J'ai déjà un tableau qui va de 0 à 400 pour l’abscisse.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    if (current >= previous + 100 ){
          for (int i=0; i<400; i++){
                regimeMemory[i] = regimeMemory[i+1];
          }
          regimeMemory[400] = (int) regime;
          previous = current;
    }
    J'aimerais savoir comment tracer les valeurs de ce tableau (variant entre 0 et 10000) dans un graphique, qui s'actualise avec "glissement vers la gauche".
    J'ai bien essayé avec la librairie JFreeChart mais je ne m'en sors pas car je débute vraiment.

    Merci d'avance pour votre aide

  2. #2
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2019
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Nièvre (Bourgogne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Transports

    Informations forums :
    Inscription : Octobre 2019
    Messages : 4
    Points : 5
    Points
    5
    Par défaut Réponse trouvé !!
    Un exemple tout fait avec la librairie JFreeChart :

    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
     
     
    package org.jfree.chart.demo;
     
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    import javax.swing.JButton;
    import javax.swing.JPanel;
     
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.axis.ValueAxis;
    import org.jfree.chart.plot.XYPlot;
    import org.jfree.data.time.Millisecond;
    import org.jfree.data.time.TimeSeries;
    import org.jfree.data.time.TimeSeriesCollection;
    import org.jfree.data.xy.XYDataset;
    import org.jfree.ui.ApplicationFrame;
    import org.jfree.ui.RefineryUtilities;
     
    /**
     * A demonstration application showing a time series chart where you can dynamically add
     * (random) data by clicking on a button.
     *
     */
    public class DynamicDataDemo extends ApplicationFrame implements ActionListener {
     
        /** The time series data. */
        private TimeSeries series;
     
        /** The most recent value added. */
        private double lastValue = 100.0;
     
        /**
         * Constructs a new demonstration application.
         *
         * @param title  the frame title.
         */
        public DynamicDataDemo(final String title) {
     
            super(title);
            this.series = new TimeSeries("Random Data", Millisecond.class);
            final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series);
            final JFreeChart chart = createChart(dataset);
     
            final ChartPanel chartPanel = new ChartPanel(chart);
            final JButton button = new JButton("Add New Data Item");
            button.setActionCommand("ADD_DATA");
            button.addActionListener(this);
     
            final JPanel content = new JPanel(new BorderLayout());
            content.add(chartPanel);
            content.add(button, BorderLayout.SOUTH);
            chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
            setContentPane(content);
     
        }
     
        /**
         * Creates a sample chart.
         * 
         * @param dataset  the dataset.
         * 
         * @return A sample chart.
         */
        private JFreeChart createChart(final XYDataset dataset) {
            final JFreeChart result = ChartFactory.createTimeSeriesChart(
                "Dynamic Data Demo", 
                "Time", 
                "Value",
                dataset, 
                true, 
                true, 
                false
            );
            final XYPlot plot = result.getXYPlot();
            ValueAxis axis = plot.getDomainAxis();
            axis.setAutoRange(true);
            axis.setFixedAutoRange(60000.0);  // 60 seconds
            axis = plot.getRangeAxis();
            axis.setRange(0.0, 200.0); 
            return result;
        }
     
     
        /**
         * Handles a click on the button by adding new (random) data.
         *
         * @param e  the action event.
         */
        public void actionPerformed(final ActionEvent e) {
            if (e.getActionCommand().equals("ADD_DATA")) {
                final double factor = 0.90 + 0.2 * Math.random();
                this.lastValue = this.lastValue * factor;
                final Millisecond now = new Millisecond();
                System.out.println("Now = " + now.toString());
                this.series.add(new Millisecond(), this.lastValue);
            }
        }
     
        /**
         * Starting point for the demonstration application.
         *
         * @param args  ignored.
         */
        public static void main(final String[] args) {
     
            final DynamicDataDemo demo = new DynamicDataDemo("Dynamic Data Demo");
            demo.pack();
            RefineryUtilities.centerFrameOnScreen(demo);
            demo.setVisible(true);
     
        }
     
    }

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

Discussions similaires

  1. Créer des graphiques
    Par zorba49 dans le forum ASP
    Réponses: 3
    Dernier message: 21/02/2006, 10h14
  2. [Graphique] Créer des graphiques en PHP
    Par neXistPa dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 08/01/2006, 13h26
  3. Comment créer des onglets "glissants"
    Par miniil dans le forum Composants VCL
    Réponses: 10
    Dernier message: 03/06/2005, 22h24
  4. Réponses: 31
    Dernier message: 28/03/2005, 17h23
  5. Créer un graphique en GIF sous DELPHI pour du web
    Par Thom@s dans le forum Web & réseau
    Réponses: 20
    Dernier message: 08/07/2004, 15h40

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