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] Affichage des années en abscisse (2,005 au lieu de 2005)


Sujet :

2D Java

  1. #1
    Membre du Club
    Inscrit en
    Juillet 2005
    Messages
    111
    Détails du profil
    Informations forums :
    Inscription : Juillet 2005
    Messages : 111
    Points : 50
    Points
    50
    Par défaut [JFreeChart] Affichage des années en abscisse (2,005 au lieu de 2005)
    Bonjour à tous,

    Je voudrais afficher un graphe avec :

    ChartFactory.createXYLineChart(title, cat1, cat2, categorydataset, PlotOrientation.VERTICAL, true, true, false);

    Le graphe s'affiche bien mais les années affichées en abcisse sont sous la forme (1,995) au lieu de 1995 : ChartFactory rajoute un séparateur de millier.

    Voici mon code qui créé mon categorydataset (les valeur à donner au createXYLineChart) :


    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
     
     
    public static ArrayList extractDataYear_NVResults(String Filename){
    		ArrayList<ArrayList> list = new ArrayList();
    		Workbook workbook;		  
    		ArrayList listItem;
    		Sheet sheet;   
    		Object objContent;
    		String strContent;
    		Integer intResultTypeCount;
    		Integer intAnneeDebut = 0;
    		Integer intAnneeFin = 0;
    		Integer intAnneeIncr = 0;
    		Integer intTotalTmp = 0;
     
    		try{  
    			workbook = Workbook.getWorkbook(new File(Filename)); 
    			sheet = workbook.getSheet("dashboard_years");								
     
    			intResultTypeCount = 5;
     
    			intAnneeDebut = 1995; 
    			intAnneeIncr = 1;
     
    			intAnneeFin= 2007;
     
    			//Recherche dans le tableau Excel les valeurs pour le graphe
    			int i=4;	
    			for ( i=4; i<intResultTypeCount; i++){
     
    				listItem = new ArrayList();
     
    				listItem.add(sheet.getCell(0,i).getContents());
    				int j=1;
    				for(int l = intAnneeDebut; l<=intAnneeFin; l++)
    				{	
     
    					if (sheet.getCell(j,i).getContents() == null)
    					{			
    						strContent = "0";
    					}  									
     
    					strContent = sheet.getCell(j,i).getContents();				
    					listItem.add( strContent );
     
    					j = j + 10;
    				}
    				list.add( listItem );				
    			}
    		}
    		catch(Exception  e)
    		{
     
    		} 
    		return list;
    	}
     
    //*********************************************************
    private static XYDataset createDataset(String base, String cat1, String cat2, String dataDirectory, String flag, String type, String ResultType, int intBeginYear){
     
    	XYSeriesCollection  dataset = new XYSeriesCollection ();
     
     
    			String filename = dataDirectory + base + "_Results.xls";
    			ArrayList<ArrayList> data = new ArrayList();
    			ArrayList<String> curveTitle = new ArrayList();
    			String period = type;
    			int nb;
     
    				data = BARResultsList.extractDataYear_NVResults(filename);
     
    				for(int i=0; i<data.size(); i++){
     
    					int year = intBeginYear; 
    					int months = 3;
    					XYSeries series;
    					if(flag.equals("NVresults") {
    						series = new XYSeries( (String)(data.get(i)).get(0) );
    						for(int j=1; j<(data.get(i)).size(); j++){
    							series.add(year, Integer.parseInt( (String)(data.get(i)).get(j)) );
    							year++;
    						}
    					}
    					dataset.addSeries(series);
    				}
     
    		return dataset;
    }
     
     
    //******************************************************************
     
    public static JFreeChart createChart(String base, String title, String cat1, String cat2, String dataDirectory, String flag, String type, String ResultType, int intBeginYear)  {
     
     
    		XYDataset categorydataset = createDataset(base, cat1, cat2, dataDirectory, flag, type, ResultType, intBeginYear);
    		JFreeChart jfreechart = ChartFactory.createXYLineChart(title, cat1, cat2, categorydataset, PlotOrientation.VERTICAL, true, true, false); 
    		//get a reference to the plot for further customisation...
     
    		return jfreechart; 
    		} 
    	}
    Excusez-moi pour la longueur du code, mais en gros je vais chercher des valeurs dans un tableau Excel et je contruis un ArrayList qui permet de construire un XYDataset (avec les années en première position) pour créer le graphe.

    Merci beaucoup pour votre aide.

    Laurent.

  2. #2
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Je pense que tu devrais plutôt créer un TimeSeriesChart avec une TimeSeriesCollection de TimeSeries.

  3. #3
    Membre du Club
    Inscrit en
    Juillet 2005
    Messages
    111
    Détails du profil
    Informations forums :
    Inscription : Juillet 2005
    Messages : 111
    Points : 50
    Points
    50
    Par défaut
    c_nvy :

    merci beaucoup pour ta réponse, mais le graphe que je veux créer est tout simple : il s'agit d'un graphe de courbes avec abcisses et ordonnées.

    Que fait le TimeSeriesChart ?

    Laurent.

  4. #4
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    A time series chart is an XYPlot with a DateAxis for the x-axis and a NumberAxis for the y-axis.
    En fait, c'est aussi un graphe simple de courbes avec en abscisse des données de type Date, comme l'année par exemple.

  5. #5
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Ci-dessous un exemple dont tu peux t'inspirer :
    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
    import java.awt.Color;
    import java.text.SimpleDateFormat;
     
    import javax.swing.JPanel;
     
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.axis.DateAxis;
    import org.jfree.chart.axis.DateTickUnit;
    import org.jfree.chart.plot.XYPlot;
    import org.jfree.data.time.Month;
    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.RectangleInsets;
    import org.jfree.ui.RefineryUtilities;
     
    /** 
     * A time series chart. 
     */ 
    public class TimeSeriesDemo extends ApplicationFrame { 
     
        /** 
         * A demonstration application showing how to create a simple time series 
         * chart.  This example uses monthly data. 
         * 
         * @param title  the frame title. 
         */ 
        public TimeSeriesDemo(String title) { 
            super(title); 
            JPanel chartPanel = createDemoPanel(); 
            setContentPane(chartPanel); 
        } 
     
        /** 
         * Creates a chart. 
         * 
         * @param dataset  a dataset. 
         * 
         * @return A chart. 
         */ 
        private static JFreeChart createChart(XYDataset dataset) { 
     
            JFreeChart chart = ChartFactory.createTimeSeriesChart( 
                "TimeSeriesChart", 	// title 
                "",		            // x-axis label 
                "",				    // y-axis label 
                dataset,            // data 
                true,               // create legend? 
                true,               // generate tooltips? 
                false               // generate URLs? 
            ); 
     
            chart.setBackgroundPaint(Color.white); 
     
            XYPlot plot = (XYPlot) chart.getPlot(); 
            plot.setBackgroundPaint(Color.lightGray); 
            plot.setDomainGridlinePaint(Color.white); 
            plot.setRangeGridlinePaint(Color.white); 
            plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); 
            plot.setDomainCrosshairVisible(true); 
            plot.setRangeCrosshairVisible(true); 
     
            DateAxis axis = (DateAxis) plot.getDomainAxis(); 
            axis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1)); 
            axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); 
            axis.setVerticalTickLabels(true);
     
            return chart; 
     
        } 
     
        /** 
         * Creates a dataset, consisting of one series of monthly data. 
         * 
         * @return The dataset. 
         */ 
        private static XYDataset createDataset() { 
     
            TimeSeries s1 = new TimeSeries("Series 1", Month.class); 
            s1.add(new Month(1, 2007), 5500000); 
            s1.add(new Month(2, 2007), 3360000); 
            s1.add(new Month(3, 2007), 2360000); 
            s1.add(new Month(4, 2007), 5500000); 
            s1.add(new Month(5, 2007), 3440000); 
            s1.add(new Month(6, 2007), 4380000); 
            s1.add(new Month(7, 2007), 4800000); 
            s1.add(new Month(8, 2007), 3960000); 
            s1.add(new Month(9, 2007), 5300000); 
            s1.add(new Month(10, 2007), 5200000); 
            s1.add(new Month(11, 2007), 3440000); 
            s1.add(new Month(12, 2007), 4380000); 
     
            TimeSeriesCollection dataset = new TimeSeriesCollection(); 
            dataset.addSeries(s1);
     
            return dataset; 
        } 
     
        /** 
         * Creates a panel for the demo (used by SuperDemo.java). 
         * 
         * @return A panel. 
         */ 
        public static JPanel createDemoPanel() { 
            JFreeChart chart = createChart(createDataset()); 
            return new ChartPanel(chart); 
        } 
     
        /** 
         * Starting point for the demonstration application. 
         * 
         * @param args  ignored. 
         */ 
        public static void main(String[] args) { 
     
            TimeSeriesDemo demo = new TimeSeriesDemo( 
                "Time Series Chart Demo" 
            ); 
            demo.pack(); 
            RefineryUtilities.centerFrameOnScreen(demo); 
            demo.setVisible(true); 
     
        }
    }

Discussions similaires

  1. Affichage des fichiers uploadés de cette année uniquement
    Par Mlle JACQUES Hélène dans le forum Langage
    Réponses: 20
    Dernier message: 02/02/2015, 16h07
  2. [Vxi3] Affichage des valeurs d'abscisse
    Par Gali-galou dans le forum Webi
    Réponses: 2
    Dernier message: 22/11/2011, 11h42
  3. Réponses: 2
    Dernier message: 21/04/2008, 21h18
  4. Réponses: 1
    Dernier message: 27/06/2007, 08h44
  5. [VB6] [Flexgrid] Format d'affichage des numériques
    Par yansolo dans le forum VB 6 et antérieur
    Réponses: 5
    Dernier message: 19/10/2002, 21h00

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