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] Fixer le pas en abcsisse et en ordonnée


Sujet :

2D Java

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2018
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2018
    Messages : 5
    Par défaut [JFreeChart] Fixer le pas en abcsisse et en ordonnée
    Bonjour,

    Je commence à avec JFreeChart, et pour un de mes graphiques j'aimerais fixer le pas en ordonnée et en abcsisse pour ne pas deformer mon graph qui doit avoir une forme precise, je travaille sur la LineChartDemo6, et je ne trouve rien qu'il m'aide sur internet donc si qqn sait comment faire je suis preneur !

    Mon code est le suivant :

    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
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
     
    package graphs;
    /* ===========================================================
    * JFreeChart : a free chart library for the Java(tm) platform
    * ===========================================================
    *
    * (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
    *
    * Project Info:  http://www.jfree.org/jfreechart/index.html
    *
    * This library is free software; you can redistribute it and/or modify it under the terms
    * of the GNU Lesser General Public License as published by the Free Software Foundation;
    * either version 2.1 of the License, or (at your option) any later version.
    *
    * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    * See the GNU Lesser General Public License for more details.
    *
    * You should have received a copy of the GNU Lesser General Public License along with this
    * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
    * Boston, MA 02111-1307, USA.
    *
    * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
    * in the United States and other countries.]
    *
    * -------------------
    * LineChartDemo6.java
    * -------------------
    * (C) Copyright 2004, by Object Refinery Limited and Contributors.
    *
    * Original Author:  David Gilbert (for Object Refinery Limited);
    * Contributor(s):   -;
    *
    * $Id: LineChartDemo6.java,v 1.5 2004/04/26 19:11:55 taqua Exp $
    *
    * Changes
    * -------
    * 27-Jan-2004 : Version 1 (DG);
    * 
    */
     
     
    import java.awt.Color;
     
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.axis.NumberAxis;
    import org.jfree.chart.plot.PlotOrientation;
    import org.jfree.chart.plot.XYPlot;
    import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
    import org.jfree.data.xy.XYDataset;
    import org.jfree.data.xy.XYSeries;
    import org.jfree.data.xy.XYSeriesCollection;
    import org.jfree.ui.ApplicationFrame;
    import org.jfree.ui.RefineryUtilities;
    import org.jfree.ui.*;
     
    /**
    * A simple demonstration application showing how to create a line chart using data from an
    * {@link XYDataset}.
    *
    */
    public class LineChartDemo6 extends ApplicationFrame {
     
       /**
        * Creates a new demo.
        *
        * @param title  the frame title.
        */
       public LineChartDemo6(final String title) {
     
           super(title);
     
           final XYDataset dataset = createDataset();
           final JFreeChart chart = createChart(dataset);
           final ChartPanel chartPanel = new ChartPanel(chart);
           chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
           setContentPane(chartPanel);
     
       }
     
       /**
        * Creates a sample dataset.
        * 
        * @return a sample dataset.
        */
       private XYDataset createDataset() {
     
           final XYSeries series1 = new XYSeries("First");
           series1.add(1.0, 1.0);
           series1.add(2.0, 4.0);
           series1.add(3.0, 3.0);
           series1.add(4.0, 5.0);
           series1.add(5.0, 5.0);
           series1.add(6.0, 7.0);
           series1.add(7.0, 7.0);
           series1.add(8.0, 8.0);
     
           final XYSeries series2 = new XYSeries("Second");
           series2.add(1.0, 5.0);
           series2.add(2.0, 7.0);
           series2.add(3.0, 6.0);
           series2.add(4.0, 8.0);
           series2.add(5.0, 4.0);
           series2.add(6.0, 4.0);
           series2.add(7.0, 2.0);
           series2.add(8.0, 1.0);
     
           final XYSeries series3 = new XYSeries("Third");
           series3.add(3.0, 4.0);
           series3.add(4.0, 3.0);
           series3.add(5.0, 2.0);
           series3.add(6.0, 3.0);
           series3.add(7.0, 6.0);
           series3.add(8.0, 3.0);
           series3.add(9.0, 4.0);
           series3.add(10.0, 3.0);
     
           final XYSeriesCollection dataset = new XYSeriesCollection();
           dataset.addSeries(series1);
           dataset.addSeries(series2);
           dataset.addSeries(series3);
     
           return dataset;
     
       }
     
       /**
        * Creates a chart.
        * 
        * @param dataset  the data for the chart.
        * 
        * @return a chart.
        */
       private JFreeChart createChart(final XYDataset dataset) {
     
           // create the chart...
           final JFreeChart chart = ChartFactory.createXYLineChart(
               "Line Chart Demo 6",      // chart title
               "X",                      // x axis label
               "Y",                      // y axis label
               dataset,                  // data
               PlotOrientation.VERTICAL,
               true,                     // include legend
               true,                     // tooltips
               false                     // urls
           );
     
           // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
           chart.setBackgroundPaint(Color.white);
     
    //       final StandardLegend legend = (StandardLegend) chart.getLegend();
     //      legend.setDisplaySeriesShapes(true);
     
           // get a reference to the plot for further customisation...
           final XYPlot plot = chart.getXYPlot();
           plot.setBackgroundPaint(Color.lightGray);
       //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
           plot.setDomainGridlinePaint(Color.white);
           plot.setRangeGridlinePaint(Color.white);
     
           final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
           renderer.setSeriesLinesVisible(0, false);
           renderer.setSeriesShapesVisible(1, false);
           plot.setRenderer(renderer);
     
           // change the auto tick unit selection to integer units only...
           final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
           rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
           // OPTIONAL CUSTOMISATION COMPLETED.
     
           return chart;
     
       }
     
       // ****************************************************************************
       // * JFREECHART DEVELOPER GUIDE                                               *
       // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
       // * to purchase from Object Refinery Limited:                                *
       // *                                                                          *
       // * http://www.object-refinery.com/jfreechart/guide.html                     *
       // *                                                                          *
       // * Sales are used to provide funding for the JFreeChart project - please    * 
       // * support us so that we can continue developing free software.             *
       // ****************************************************************************
     
       /**
        * Starting point for the demonstration application.
        *
        * @param args  ignored.
        */
       public static void main(final String[] args) {
     
           final LineChartDemo6 demo = new LineChartDemo6("Line Chart Demo 6");
           demo.pack();
           RefineryUtilities.centerFrameOnScreen(demo);
           demo.setVisible(true);
     
       }
     
    }

  2. #2
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 087
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 087
    Par défaut
    Difficile de te répondre sans vraiment voir ce que tu as et ce que tu voudrais. Peux tu essayer de le dessiner ou je ne sais quoi ?
    (Les "ça ne marche pas", même écrits sans faute(s), vous porteront discrédit ad vitam æternam et malheur pendant 7 ans)

    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  3. #3
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2018
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2018
    Messages : 5
    Par défaut
    C'est vrai que je n'ai pas mis d'illustration.

    En fait mon but est de reproduire la forme d'une machine qui existe (avec ses dimensions) sur mon graphique, donc pour cela il faut que l'unité des abscisses soit la même que celle des ordonnées, pour avoir un prévisualisation pas trop déformée, j'illustre :

    Pour l'instant j'ai ceci :

    Nom : CaptureNonCalibrée.PNG
Affichages : 519
Taille : 80,5 Ko

    Et j'aimerais obtenir quelques soit les circonstances ceci :

    Nom : Capture.PNG
Affichages : 516
Taille : 47,1 Ko

    Pour faire simple, je souhaite que une unité en abscisse et une unité en ordonnée soit de même taille visuellement.
    Peut-on l’imposer sur un JFreechart ?

    Je vous met ce que j'utilise pour l'instant pour mettre en forme mon graphique :
    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
     
    private JFreeChart createChart(final XYDataset dataset) {
     
     
     
             // create the chart...
             final JFreeChart chart = ChartFactory.createXYLineChart(
                 "Preview",      // chart title
                 "x - coordinate [m]",                      // x axis label
                 "y - coordinate [m]",                      // y axis label
                 dataset,                  // data
                 PlotOrientation.VERTICAL,
                 true,                     // include legend
                 true,                     // tooltips
                 false                     // urls
             );
     
             // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
             chart.setBackgroundPaint(Color.white);
     
     
     
    //         final StandardLegend legend = (StandardLegend) chart.getLegend();
    //         legend.setDisplaySeriesShapes(true);
     
             // get a reference to the plot for further customisation...
             final XYPlot plot = chart.getXYPlot();
             plot.setBackgroundPaint(Color.white);
    //         plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
             plot.setDomainGridlinePaint(Color.black);
             plot.setRangeGridlinePaint(Color.black);
     
          // Titre legende abscisse
             ValueAxis axis = plot.getDomainAxis();         
             // Titre legende ordonnée
             ValueAxis vaxis = plot.getRangeAxis();
     
     
     
             final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
     
             // We define if we want see the line between points or not
             renderer.setSeriesLinesVisible(0, true);
             renderer.setSeriesLinesVisible(1, true);
     
             // We define if we want see the shapes or not
             renderer.setSeriesShapesVisible(0, false);
             renderer.setSeriesShapesVisible(1, false);
             renderer.setSeriesShapesVisible(3, false);
             renderer.setSeriesShapesVisible(4, false);
             renderer.setSeriesShapesVisible(5, false);
             renderer.setSeriesShapesVisible(6, false);
             renderer.setSeriesShapesVisible(7, false);
             renderer.setSeriesShapesVisible(8, false);
     
             // We define the colors of the curves
             renderer.setSeriesPaint(0, Color.RED);
             renderer.setSeriesPaint(1, Color.RED);
             renderer.setSeriesPaint(2, Color.BLACK);
             renderer.setSeriesPaint(3, Color.BLUE);
             renderer.setSeriesPaint(4, Color.BLUE);
             renderer.setSeriesPaint(5, Color.BLUE);
             renderer.setSeriesPaint(6, Color.BLUE);
             renderer.setSeriesPaint(7, Color.BLUE);
             renderer.setSeriesPaint(8, Color.BLUE);
             renderer.setSeriesPaint(9, Color.BLACK);
     
             // We define the thickness of the curve
             renderer.setSeriesStroke(0, new BasicStroke(1.0f));
             renderer.setSeriesStroke(1, new BasicStroke(1.0f));
             // Creation of a shape for the Origine
             Shape cross = ShapeUtilities.createDiagonalCross(15, 0);
             cross = ShapeUtilities.rotateShape(cross, Math.PI/4, 0, 0);
             renderer.setSeriesShape(2, cross);
             renderer.setSeriesShape(9, cross);
     
     
             //Remove the auxiliaries series from the legend
             renderer.setSeriesVisibleInLegend(2, false);
             renderer.setSeriesVisibleInLegend(3, false);
             renderer.setSeriesVisibleInLegend(4, false);
             renderer.setSeriesVisibleInLegend(5, false);
             renderer.setSeriesVisibleInLegend(6, false);
             renderer.setSeriesVisibleInLegend(7, false);
             renderer.setSeriesVisibleInLegend(8, false);
             renderer.setSeriesVisibleInLegend(9, false);
     
             plot.setRenderer(renderer);
     
             XYBlockRenderer render = new XYBlockRenderer();
             render.setSeriesVisibleInLegend(1, false);
     
             // change the auto tick unit selection to integer units only...
             final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
             rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
     
     
             // OPTIONAL CUSTOMISATION COMPLETED.
     
             return chart;
     
         }
    J'espère que j'ai éte plus claire, et si vous avez d'autres questions n'hésitez pas !

    PS : Il est vrai que j'ai écrit sans filtre ma pensé sur le précèdent post d'où la présence de certaines expressions.

  4. #4
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 087
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 087
    Par défaut
    Cela semble plus claire oui.

    Tu sembles vouloir garder un graphique au ratio 1:1.

    Je n'ai pas de solution desuite. Mais si c'est bien ça c'est déjà un bon départ de savoir la contrainte au problème.
    (Les "ça ne marche pas", même écrits sans faute(s), vous porteront discrédit ad vitam æternam et malheur pendant 7 ans)

    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  5. #5
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2018
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2018
    Messages : 5
    Par défaut
    Oui c'est tout à fait cela !

    Ok si qqn à une solution à mon problème du coup il me serait d'une grande aide !

Discussions similaires

  1. API JFreeChart : fixer vitesse de défilement de la chart de MemoryUsageDemo
    Par The Grey dans le forum API standards et tierces
    Réponses: 3
    Dernier message: 12/09/2011, 11h24
  2. Réponses: 2
    Dernier message: 27/08/2008, 12h32
  3. Réponses: 2
    Dernier message: 21/04/2008, 22h18
  4. Réponses: 1
    Dernier message: 24/01/2008, 22h41
  5. [JFreeChart] Fixer l'échelle des abscisses
    Par ahury dans le forum 2D
    Réponses: 1
    Dernier message: 03/05/2007, 18h14

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