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

AWT/Swing Java Discussion :

Affichage des valeurs dans la courbe


Sujet :

AWT/Swing Java

  1. #1
    Débutant  
    Inscrit en
    Mars 2008
    Messages
    1 123
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 1 123
    Points : 170
    Points
    170
    Par défaut Affichage des valeurs dans la courbe
    bonjour à tous

    je veux afficher une courbe et voici mon code:
    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
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.ComponentOrientation;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
     
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.axis.AxisLocation;
    import org.jfree.chart.axis.NumberAxis;
    import org.jfree.chart.plot.CategoryPlot;
    import org.jfree.chart.plot.PlotOrientation;
     
    import org.jfree.chart.renderer.category.LineAndShapeRenderer;
    import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
    import org.jfree.data.category.CategoryDataset;
    import org.jfree.data.category.DefaultCategoryDataset;
    import org.jfree.ui.ApplicationFrame;
    import org.jfree.ui.RefineryUtilities;
     
     
    public class Dessin   {
     
        private CategoryPlot plot;
        private int secondaryDatasetIndex = 0;
        private static double[] a= new double[9];
        private JPanel p;
     
        public Dessin(final double[] a) {
     
        final CategoryDataset dataset1 = createRandomDataset("");
        final JFreeChart chart = ChartFactory.createLineChart( "", "", "",dataset1, PlotOrientation.HORIZONTAL, false, true, false);
        chart.setBackgroundPaint(Color.white);
        this.plot = chart.getCategoryPlot();
        this.plot.setBackgroundPaint(Color.WHITE);
        this.plot.setDomainGridlinePaint(Color.orange);
        this.plot.setRangeGridlinePaint(Color.orange);
        plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
        plot.setRangeGridlinesVisible(true);
        plot.setDomainGridlinesVisible(true);
     
        final NumberAxis rangeAxis = (NumberAxis) this.plot.getRangeAxis();
        rangeAxis.setAutoRangeIncludesZero(false);
        final JPanel content = new JPanel(new BorderLayout());
        final ChartPanel chartPanel = new ChartPanel(chart);
        content.add(chartPanel);
     
     
     
        p = new JPanel(new FlowLayout());
        content.add(p, BorderLayout.SOUTH);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        JFrame jFrame = new JFrame();
    	jFrame.setSize(805, 605);
     
    	jFrame.setTitle("Bec 96 1.0.0");
    	jFrame.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    	jFrame.setVisible(true);
    	jFrame.setLocationRelativeTo(null);
     
    	jFrame.setContentPane(content);
     
        }
     
        private CategoryDataset createRandomDataset(final String name) {
            final DefaultCategoryDataset result = new DefaultCategoryDataset();
            double value = 100.0;
            for (int i = 0; i < 9; i++) {
                final String key = "hhh"+i;
                value =  (a[i]);
                result.addValue(value, name, key);
            }
            return result;
        }
     
     
     
        public static void main(final String[] args) {
     
        	for (int i=0;i<9;i++)
        	{
        		a[i]=i*2;
        	}
            final Dessin demo = new Dessin(a);
     
     
     
        }
     
    }
    j'ai deux petits soucis:

    1) j'ai réussi à faire l'axe des Y en haut mais je veux aussi afficher l'axe des X à droit mais je n'ai pas pu le faire

    2) comment je peux afficher les valeur sur ma courbe?????


    Merci

  2. #2
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Janvier 2010
    Messages
    312
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2010
    Messages : 312
    Points : 533
    Points
    533
    Par défaut
    Bonjour,

    1 - ce n'est pas le RangeAxis que tu veux bouger mais le DomainAxis et l'index de l'axe est 0 donc remplace :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    par

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    plot.setDomainAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT);
    2 - pour afficher les points il faut parametrer le LineAndShapeRenderer

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    LineAndShapeRenderer renderer
    = (LineAndShapeRenderer) plot.getRenderer();
        renderer.setBaseShapesVisible(true); 
        renderer.setUseFillPaint(true);
        renderer.setBaseFillPaint(Color.white);

    au final ça donne :

    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
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.ComponentOrientation;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
     
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.axis.AxisLocation;
    import org.jfree.chart.axis.NumberAxis;
    import org.jfree.chart.plot.CategoryPlot;
    import org.jfree.chart.plot.PlotOrientation;
     
    import org.jfree.chart.renderer.category.LineAndShapeRenderer;
    import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
    import org.jfree.data.category.CategoryDataset;
    import org.jfree.data.category.DefaultCategoryDataset;
    import org.jfree.ui.ApplicationFrame;
    import org.jfree.ui.RefineryUtilities;
     
     
    public class Dessin   {
     
        private CategoryPlot plot= new CategoryPlot();
        private int secondaryDatasetIndex = 0;
        private static double[] a= new double[9];
        private JPanel p;
     
        public Dessin(final double[] a) {
     
        final CategoryDataset dataset1 = createRandomDataset("");
        final JFreeChart chart = ChartFactory.createLineChart( "", "", "",dataset1, PlotOrientation.HORIZONTAL, false, true, false);
        chart.setBackgroundPaint(Color.white);
        this.plot = chart.getCategoryPlot();
        this.plot.setBackgroundPaint(Color.white);
        this.plot.setDomainGridlinePaint(Color.orange);
        this.plot.setRangeGridlinePaint(Color.orange);
        this.plot.setDomainAxisLocation(0,AxisLocation.BOTTOM_OR_RIGHT);
        this.plot.setRangeGridlinesVisible(true);
        this.plot.setDomainGridlinesVisible(true);
     
        LineAndShapeRenderer renderer
    = (LineAndShapeRenderer) plot.getRenderer();
        renderer.setBaseShapesVisible(true); 
        renderer.setUseFillPaint(true);
        renderer.setBaseFillPaint(Color.white);
     
        final NumberAxis rangeAxis = (NumberAxis) this.plot.getRangeAxis();
        rangeAxis.setAutoRangeIncludesZero(false);
        final JPanel content = new JPanel(new BorderLayout());
        final ChartPanel chartPanel = new ChartPanel(chart);
        content.add(chartPanel);
     
     
     
        p = new JPanel(new FlowLayout());
        content.add(p, BorderLayout.SOUTH);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        JFrame jFrame = new JFrame();
    	jFrame.setSize(805, 605);
     
    	jFrame.setTitle("Bec 96 1.0.0");
    	jFrame.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
     
    	jFrame.setLocationRelativeTo(null);
     
    	jFrame.setContentPane(content);
     jFrame.setVisible(true);
        }
     
        private CategoryDataset createRandomDataset(final String name) {
            final DefaultCategoryDataset result = new DefaultCategoryDataset();
            double value = 100.0;
            for (int i = 0; i < 9; i++) {
                final String key = "hhh"+i;
                value =  (a[i]);
                result.addValue(value, name, key);
            }
            return result;
        }
     
     
     
        public static void main(final String[] args) {
     
        	for (int i=0;i<9;i++)
        	{
        		a[i]=i*2;
        	}
            final Dessin demo = new Dessin(a);
     
     
     
        }
     
    }

  3. #3
    Débutant  
    Inscrit en
    Mars 2008
    Messages
    1 123
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 1 123
    Points : 170
    Points
    170
    Par défaut
    Merci

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

Discussions similaires

  1. Affichage des valeurs séléctionnées dans un ListView
    Par TomDuBouchon dans le forum Windows Forms
    Réponses: 2
    Dernier message: 01/09/2009, 15h47
  2. [Hyperion-Explorer] Affichage des valeurs dans Pivot
    Par jdmbh dans le forum EPM (Hyperion)
    Réponses: 1
    Dernier message: 15/11/2008, 22h29
  3. Controler le format d'affichage des valeurs numeriques dans un statictext
    Par soforan dans le forum Interfaces Graphiques
    Réponses: 4
    Dernier message: 18/06/2008, 20h57
  4. Affichage des valeurs disponibles dans une zone de liste déroulante
    Par azerty dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 04/06/2007, 12h29
  5. [SQL] Affichage des valeurs nulles dans un Count
    Par at_first dans le forum Access
    Réponses: 4
    Dernier message: 06/03/2007, 11h07

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