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] Limiter l'axe des temps à LA SEMAINE EN COURS


Sujet :

2D Java

  1. #1
    Futur Membre du Club
    Inscrit en
    Mars 2007
    Messages
    13
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 13
    Points : 7
    Points
    7
    Par défaut [JFreeChart] Limiter l'axe des temps à LA SEMAINE EN COURS
    Super... Enfin un forum avec des gens qui connaissent JFreeChart...

    Alors voila :
    J'ai réussis à créer mes graphes comme il faut MAIS mon problème c'est que j'aimerais limiter l'affichage des données SEULEMENT DE LA SEMAINE EN COURS DU LUNDI AU VENDREDI...

    Qui peut m'aiguiller?

    Voila ce que j'ai pour l'instant :

  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
    As-tu essayé d'utiliser les méthodes setMinimumDate et setMaximumDate de la classe DateAxis ?

  3. #3
    Membre éclairé Avatar de remika
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    806
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 806
    Points : 861
    Points
    861
    Par défaut
    Super... Enfin un forum avec des gens qui connaissent JFreeChart...
    Le forum de JFreechart est aussi super actif, et notamment le fondateur du projet David Gilbert répond à toutes les questions
    Seule contrainte, c'est en anglais, mais bon on fait de l'info...

  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
    Citation Envoyé par remika
    Le forum de JFreechart est aussi super actif, et notamment le fondateur du projet David Gilbert répond à toutes les questions
    Seule contrainte, c'est en anglais, mais bon on fait de l'info...
    +1

  5. #5
    Futur Membre du Club
    Inscrit en
    Mars 2007
    Messages
    13
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 13
    Points : 7
    Points
    7
    Par défaut
    Je dois rentrer un argument de type date, mais comment dois-je faire pour lui donner la date de il y a 7 jours?

    Il veut un argument de type Date! Sous quelle forme ça se présente? "yyyy-mm-dd" ou "dd-mm-yyyy" ou un entier, ou bien...?

    Have a look :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    timeAxis.setMinimumDate(__________) ;

  6. #6
    Membre éclairé Avatar de remika
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    806
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 806
    Points : 861
    Points
    861
    Par défaut
    Les dates se manipulent en Java principalement avec les classes Calendar et Date. La méthode add de Calendar permet de faire des calculs "habituels".

    cf Gestion des dates en java et Javadoc

  7. #7
    Futur Membre du Club
    Inscrit en
    Mars 2007
    Messages
    13
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 13
    Points : 7
    Points
    7
    Par défaut
    Ca plante...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    GregorianCalendar calendar = new java.util.GregorianCalendar(); 
    // Je récupère la date actuelle
    calendar.setTime( new Date() ); 
    // A partir de là, je récupère la date de la semaine dernière
    calendar.add (Calendar.DATE, -7);
    Ca ça marche. Je l'ai vérifié en debug. 25 mai - 7 = 18 mai.
    Mais la ça plante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    DateAxis timeAxis = new DateAxis("");
    // J'ajoute le FAMEUX paramètre de type Date, comme demandé			
    timeAxis.setMinimumDate(calendar.getTime()) ;
    Et BIM!!!!! Ca plante

  8. #8
    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
    Et comme ceci ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    	DateAxis dateAxis = (DateAxis) plot.getDomainAxis() ;
    	dateAxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1)) ;
     
    	// 1er jour de la semaine en cours
    	Calendar minCalendar = new GregorianCalendar(); 
    	minCalendar.setTime(new Date());
    	minCalendar.set(Calendar.DAY_OF_WEEK ,minCalendar.getFirstDayOfWeek());
    	dateAxis.setMinimumDate(minCalendar.getTime());

  9. #9
    Futur Membre du Club
    Inscrit en
    Mars 2007
    Messages
    13
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 13
    Points : 7
    Points
    7
    Par défaut
    Noooon... Désolé, j'suis mauvais... Voici mon code :
    J'ai mis en ROUGE la zone à regarder s'il vous plait...


    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
    public static String generateXYChart(String section, HttpSession session, PrintWriter pw) {
            String filename = null;
            try {
                //  Retrieve list of WebHits
                WebHitDataSet whDataSet = new WebHitDataSet();
                ArrayList list = whDataSet.getDataByHitDate(section);
    
                //  Throw a custom NoDataException if there is no data
                if (list.size() == 0) {
                    System.out.println("No data has been found");
                    throw new NoDataException();
                }
    
                //  Create and populate an XYSeries Collection
                XYSeries dataSeries = new XYSeries("Valeur");
                XYSeries dataSeries2 = new XYSeries("Valeur");
    
                Iterator iter = list.listIterator();
                while (iter.hasNext()) {
                    WebHit wh = (WebHit)iter.next();
                    dataSeries.add(wh.getHitDate().getTime(),wh.getHitCount());
                }
    
                XYSeriesCollection xyDataset = new XYSeriesCollection();
                xyDataset.addSeries(dataSeries) ;
    
                //  Create tooltip and URL generators
                SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", Locale.UK);
    
                StandardXYToolTipGenerator ttg = new StandardXYToolTipGenerator(
                        StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                        sdf, NumberFormat.getInstance());
                TimeSeriesURLGenerator urlg = new TimeSeriesURLGenerator(
                        sdf, "pie_chart.jsp", "series", "hitDate");
    
                //  Create the chart object
                DateAxis timeAxis = new DateAxis("");
                
    // SAIYUKE
                 // Ajout limites de date
                GregorianCalendar calendar = new java.util.GregorianCalendar(); 
                calendar.setTime( new Date() ); 
                // Calcul de la date de il y a 7 jours
                calendar.add (Calendar.DATE, -7);
                // Je crée ma limite minimum
               timeAxis.setMinimumDate(calendar.getTime()) ;
    
                NumberAxis valueAxis = new NumberAxis("");
                valueAxis.setAutoRangeIncludesZero(false);  // override default
                StandardXYItemRenderer renderer = new StandardXYItemRenderer(
                        StandardXYItemRenderer.LINES + StandardXYItemRenderer.SHAPES,
                        ttg, urlg);
                renderer.setShapesFilled(true);
                XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, renderer);
                JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
                chart.setBackgroundPaint(java.awt.Color.white);
    
                //  Write the chart image to the temporary directory
                ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
                filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);
    
                //  Write the image map to the PrintWriter
                ChartUtilities.writeImageMap(pw, filename, info);
                pw.flush();
    
            } catch (NoDataException e) {
                System.out.println(e.toString());
                filename = "public_nodata_500x300.png";
            } catch (Exception e) {
                System.out.println("Exception - " + e.toString());
                e.printStackTrace(System.out);
                filename = "public_error_500x300.png";
            }
            return filename;
        }

  10. #10
    Membre éclairé Avatar de remika
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    806
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 806
    Points : 861
    Points
    861
    Par défaut
    calendar.add (Calendar.DATE, -7);
    Déjà là c'est pas plutôt des jours que tu veux ajouter ????

  11. #11
    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 t'ai donné la méthode pour trouver le premier jour de la semaine en cours, soit le lundi, comme tu as demandé au début de la discussion.
    Pourquoi ne l'appliques-tu pas ?????????

  12. #12
    Futur Membre du Club
    Inscrit en
    Mars 2007
    Messages
    13
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 13
    Points : 7
    Points
    7
    Par défaut
    CA Y EST!! C'EST PARFAIT!! J'ai retouché un peu ton code pour AUSSI limiter au dernier jour de la semaine (très simple) et pour que ça commence 1 jour avant le premier jour de la semaine (sinon on ne voyait pas très bien les valeurs pour lundi). Pour ça j'ai simplement utilisé le calendrier Locale.US vu que le leur commence un dimanche!!

    Du coup, voici mon bébé (j'ai rajouté des flèches pour afficher les tendances à la hausse ou a la baisse ^^) :
    PS : Je me suis positionné au jeudi 14/06/2007 pour mes tests donc ne vous inquiétez pas pour la date affichée là...


  13. #13
    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
    Poste ton code, ça pourra servir à quelqu'un d'autre.

    Et n'oublie pas le tag

  14. #14
    Futur Membre du Club
    Inscrit en
    Mars 2007
    Messages
    13
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 13
    Points : 7
    Points
    7
    Par défaut
    Voici tout mon code grace à quoi j'ai obtenu ça :
    (NB : Je suis parti d'un exemple qui est inclus dans JFreeChart)

    Merci encore à tous!

    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
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
     
    package graphique;
     
    import java.awt.*;
    import java.awt.geom.Ellipse2D;
    import java.io.PrintWriter;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.ArrayList;
    import java.util.GregorianCalendar;
    import java.util.Iterator;
    import java.util.Locale;
    import java.text.NumberFormat;
    import javax.servlet.http.HttpSession;
    import org.jfree.data.*;
    import org.jfree.chart.*;
    import org.jfree.chart.axis.*;
    import org.jfree.chart.renderer.BarRenderer;
    import org.jfree.chart.renderer.StandardXYItemRenderer;
    import org.jfree.chart.renderer.StackedXYAreaRenderer;
    import org.jfree.chart.renderer.XYAreaRenderer;
    import org.jfree.chart.plot.*;
    import org.jfree.chart.entity.*;
    import org.jfree.chart.labels.*;
    import org.jfree.chart.urls.*;
    import org.jfree.chart.servlet.*;
     
    /**
     * 
     * @author saiyuke
     *
     * 4 méthodes (importantes) dans cette classe :
     * - public static String generateBarChart(Date hitDate, HttpSession session, PrintWriter pw)
     * - public static String generatePieChart(Date hitDate, HttpSession session, PrintWriter pw)
     * - public static String generateXYChart(String section, HttpSession session, PrintWriter pw)
     * - public static String generateXYAreaChart(HttpSession session, PrintWriter pw)
     */
    public class WebHitChart {
     
    	public static String generateBarChart(Date hitDate, HttpSession session, PrintWriter pw) {
    		String filename = null;
    		try {
    			//  Retrieve list of WebHits
    			WebHitDataSet whDataSet = new WebHitDataSet();
    			ArrayList list = whDataSet.getDataBySection(hitDate);
     
    			//  Throw a custom NoDataException if there is no data
    			if (list.size() == 0) {
    				System.out.println("No data has been found");
    				throw new NoDataException();
    			}
     
    		 	//  Create and populate a CategoryDataset
    			Iterator iter = list.listIterator();
                DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    			while (iter.hasNext()) {
    				WebHit wh = (WebHit)iter.next();
                    dataset.addValue(new Long(wh.getHitCount()), "Hits", wh.getSection());
    			}
     
    			//  Create the chart object
    			CategoryAxis categoryAxis = new CategoryAxis("");
    			ValueAxis valueAxis = new NumberAxis("");
    			BarRenderer renderer = new BarRenderer();
    			renderer.setItemURLGenerator(new StandardCategoryURLGenerator("xy_chart.jsp","series","section"));
                renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
     
    			Plot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    			JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    			chart.setBackgroundPaint(java.awt.Color.white);
     
    			//  Write the chart image to the temporary directory
    			ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    			filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);
     
    			//  Write the image map to the PrintWriter
    			ChartUtilities.writeImageMap(pw, filename, info);
    			pw.flush();
     
    		} catch (NoDataException e) {
    			System.out.println(e.toString());
    			filename = "public_nodata_500x300.png";
    		} catch (Exception e) {
    			System.out.println("Exception - " + e.toString());
    			e.printStackTrace(System.out);
    			filename = "public_error_500x300.png";
    		}
    		return filename; 
    	}
     
    	public static String generatePieChart(Date hitDate, HttpSession session, PrintWriter pw) {
    		String filename = null;
    		try {
    			//  Retrieve list of WebHits
    			WebHitDataSet whDataSet = new WebHitDataSet();
    			ArrayList list = whDataSet.getDataBySection(hitDate);
     
    			//  Throw a custom NoDataException if there is no data
    			if (list.size() == 0) {
    				System.out.println("No data has been found");
    				throw new NoDataException();
    			}
     
    			//  Create and populate a PieDataSet
    			DefaultPieDataset data = new DefaultPieDataset();
    			Iterator iter = list.listIterator();
    			while (iter.hasNext()) {
    				WebHit wh = (WebHit)iter.next();
    				data.setValue(wh.getSection(), new Long(wh.getHitCount()));
    			}
     
    			//  Create the chart object
    			PiePlot plot = new PiePlot(data);
    			plot.setInsets(new Insets(0, 5, 5, 5));
    			plot.setURLGenerator(new StandardPieURLGenerator("xy_chart.jsp","section"));
                plot.setToolTipGenerator(new StandardPieItemLabelGenerator());
    			JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    			chart.setBackgroundPaint(java.awt.Color.white);
     
    			//  Write the chart image to the temporary directory
    			ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    			filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);
     
    			//  Write the image map to the PrintWriter
    			ChartUtilities.writeImageMap(pw, filename, info);
    			pw.flush();
     
    		} catch (NoDataException e) {
    			System.out.println(e.toString());
    			filename = "public_nodata_500x300.png";
    		} catch (Exception e) {
    			System.out.println("Exception - " + e.toString());
    			e.printStackTrace(System.out);
    			filename = "public_error_500x300.png";
    		}
    		return filename;
    	}
     
    	public static String generateXYChart(String section, HttpSession session, PrintWriter pw) {
    		String filename = null;
    		try {
    			//  Retrieve list of WebHits
    			WebHitDataSet whDataSet = new WebHitDataSet();
    			ArrayList list = whDataSet.getDataByHitDate(section);
     
    			//  Throw a custom NoDataException if there is no data
    			if (list.size() == 0) {
    				System.out.println("No data has been found");
    				throw new NoDataException();
    			}
     
    			//  Create and populate an XYSeries Collection
    			XYSeries dataSeries = new XYSeries("Valeur");
    			XYSeries dataSeries2 = new XYSeries("Valeur");
     
    			Iterator iter = list.listIterator();
    			while (iter.hasNext()) {
    				WebHit wh = (WebHit)iter.next();
    				dataSeries.add(wh.getHitDate().getTime(),wh.getHitCount());
    			}
    			// Modification SAIYUKE
    			// Essai de multi-graphes
    			XYSeriesCollection xyDataset = new XYSeriesCollection();
    			xyDataset.addSeries(dataSeries) ;
    			// Pour rajouter des courbes sur le même graphe, il faut passer par ici!!!!!!!!
    			xyDataset.addSeries(dataSeries2) ;
     
    			//  Create tooltip and URL generators
    			SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", Locale.UK);
     
    			StandardXYToolTipGenerator ttg = new StandardXYToolTipGenerator(
    					StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                        sdf, NumberFormat.getInstance());
    			TimeSeriesURLGenerator urlg = new TimeSeriesURLGenerator(
    					sdf, "pie_chart.jsp", "series", "hitDate");
     
    			//  Create the chart object
    			DateAxis timeAxis = new DateAxis("");
     
    			NumberAxis valueAxis = new NumberAxis("");
    			valueAxis.setAutoRangeIncludesZero(false);  // override default
                StandardXYItemRenderer renderer = new StandardXYItemRenderer(
                        StandardXYItemRenderer.LINES + StandardXYItemRenderer.SHAPES,
                        ttg, urlg);
                renderer.setShapesFilled(true);
    			XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, renderer);
     
    			/** SAIYUKE
                             * Ajout de la limite des dates */
    			DateAxis dateAxis = (DateAxis) plot.getDomainAxis() ;
    			dateAxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1)) ;
     
    			// 1er jour de la semaine en cours
    			Calendar minCalendar = new GregorianCalendar(Locale.US) ; 
    			minCalendar.setTime(new Date());
    			minCalendar.set(Calendar.DAY_OF_WEEK ,minCalendar.getFirstDayOfWeek());
    			dateAxis.setMinimumDate(minCalendar.getTime()); 
    			// Dernier jour de la semaine en cours
    			minCalendar.set(Calendar.DAY_OF_WEEK ,minCalendar.getFirstDayOfWeek() + 5);
    			dateAxis.setMaximumDate(minCalendar.getTime()); 
    			/** Fin ajout SAIYUKE */
     
    			JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    			chart.setBackgroundPaint(java.awt.Color.white);
     
    			//  Write the chart image to the temporary directory
    			ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    			filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);
     
    			//  Write the image map to the PrintWriter
    			ChartUtilities.writeImageMap(pw, filename, info);
    			pw.flush();
     
    		} catch (NoDataException e) {
    			System.out.println(e.toString());
    			filename = "public_nodata_500x300.png";
    		} catch (Exception e) {
    			System.out.println("Exception - " + e.toString());
    			e.printStackTrace(System.out);
    			filename = "public_error_500x300.png";
    		}
    		return filename;
    	}
     
        public static String generateXYAreaChart(HttpSession session, PrintWriter pw)
        {
            String filename = null;
     
            try
            {
                // Récupère la liste de WebHits pour chaque section et remplit un TableXYDataset
                WebHitDataSet whDataSet = new WebHitDataSet();
                // Récupère la liste des sections
                ArrayList sections = whDataSet.getSections();
                Iterator sectionIter = sections.iterator();
                DefaultTableXYDataset dataset = new DefaultTableXYDataset();
                while (sectionIter.hasNext()) {
                    String section = (String)sectionIter.next();
                    ArrayList list = whDataSet.getDataByHitDate(section);
                    XYSeries dataSeries = new XYSeries(section, true, false);
                    Iterator webHitIter = list.iterator();
                    while (webHitIter.hasNext()) {
                        WebHit webHit = (WebHit)webHitIter.next();
                        dataSeries.add(webHit.getHitDate().getTime(), webHit.getHitCount());
                    }
                    dataset.addSeries(dataSeries);
                }
     
                //  Throw a custom NoDataException if there is no data
                if (dataset.getItemCount() == 0) {
                    System.out.println("No data has been found");
                    throw new NoDataException();
                }
     
                //  Create tooltip and URL generators
                SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", Locale.UK);
                StandardXYToolTipGenerator ttg = new StandardXYToolTipGenerator(
                        StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                        sdf, NumberFormat.getInstance());
                TimeSeriesURLGenerator urlg = new TimeSeriesURLGenerator(
                        sdf, "bar_chart.jsp", "series", "hitDate");
     
                //  Create the X-Axis
                DateAxis xAxis = new DateAxis(null);
                xAxis.setLowerMargin(0.0);
                xAxis.setUpperMargin(0.0);
     
                //  Create the X-Axis
                NumberAxis yAxis = new NumberAxis(null);
                yAxis.setAutoRangeIncludesZero(true);
     
                //  Create the renderer
                StackedXYAreaRenderer renderer =
                        new StackedXYAreaRenderer(XYAreaRenderer.AREA_AND_SHAPES, ttg, urlg);
                renderer.setSeriesPaint(0, new Color(255, 255, 180));
                renderer.setSeriesPaint(1, new Color(206, 230, 255));
                renderer.setSeriesPaint(2, new Color(255, 230, 230));
                renderer.setSeriesPaint(3, new Color(206, 255, 206));
                renderer.setShapePaint(Color.gray);
                renderer.setShapeStroke(new BasicStroke(0.5f));
                renderer.setShape(new Ellipse2D.Double(-3, -3, 6, 6));
                renderer.setOutline(true);
     
                //  Create the plot
                XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
                plot.setForegroundAlpha(0.65f);
     
                //  Reconfigure Y-Axis so the auto-range knows that the data is stacked
                yAxis.configure();
     
                //  Create the chart
                JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
                chart.setBackgroundPaint(java.awt.Color.white);
     
                //  Write the chart image to the temporary directory
                ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
                filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);
     
                //  Write the image map to the PrintWriter
                ChartUtilities.writeImageMap(pw, filename, info);
                pw.flush();
     
     
            } catch (NoDataException e) {
                System.out.println(e.toString());
                filename = "public_nodata_500x300.png";
            } catch (Exception e) {
                System.out.println("Exception - " + e.toString());
                e.printStackTrace(System.out);
                filename = "public_error_500x300.png";
            }
            return filename;
        }
     
        /**
         * SAIYUKE
         * J'ai mis ce code mis en commaentaire car inutile vu que j'ai tout 
         * intégré au projet PAM (XAGA).
         */
        /*
    	public static void main(java.lang.String[] args) {
    		try {
    			SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", Locale.UK);
    			PrintWriter pw = new PrintWriter(System.out);
    			String filename = WebHitChart.generateBarChart(sdf.parse("01-Aug-2002"), null, pw);
    //			String filename = WebHitChart.generatePieChart(sdf.parse("01-Aug-2002"), null, pw);
    //			String filename = WebHitChart.generateXYChart("service", null, pw);
    			System.out.println("filename - " + filename);
     
    		} catch (Exception e) {
    			System.out.println("Exception - " + e.toString());
    			e.printStackTrace();
    		}
    		return;
    	}*/
     
    }

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

Discussions similaires

  1. [JFreeChart] Enlever un mois à l'axe des temps
    Par Ceubex dans le forum Interfaces Graphiques en Java
    Réponses: 0
    Dernier message: 24/08/2011, 15h33
  2. [JFreeChart] Gestion données axe des ordonnées
    Par franfr57 dans le forum 2D
    Réponses: 1
    Dernier message: 11/07/2008, 14h30
  3. Réponses: 2
    Dernier message: 04/03/2008, 16h23
  4. JFreeChart pb graduation axe des x
    Par Mengué georges dans le forum 2D
    Réponses: 3
    Dernier message: 05/01/2008, 20h52
  5. Réponses: 4
    Dernier message: 19/12/2007, 10h19

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