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] Séries temporelles


Sujet :

2D Java

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de habasque
    Homme Profil pro
    Ingénieur d'études
    Inscrit en
    Septembre 2006
    Messages
    530
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur d'études
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Septembre 2006
    Messages : 530
    Par défaut [JFreeChart] Séries temporelles
    salut à tous,


    je rencontre un problème pour la génération d'un graphique de séries de données temporelles.

    il s'agit de 3 courbes dont les données proviennent de 3 requêtes SQL distinctes...
    pour info, il s'agit de nombres de coups de pêches par type de bâteau par jour
    le problème est que les dataset correspondant se créent séparemment et du coup il se peut que les dates ne soient pas ordonnées...

    en pièce jointe, un exemple de bug...

    comment pallier à cela ?

    je copies également le code au cas où...

    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
     
    public class LineChartGenerator {
     
    	public static CategoryDataset createDataset() throws Exception{
     
    		final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
     
    		final String serieFierro = "Fierro";
    		final String serieArrastre = "Arrastre";
    		final String serieMadera = "Madera";
     
    		SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
    		SimpleDateFormat formatinv = new SimpleDateFormat("dd-mm");
     
    		try {
     
    			DBConnexionAction dbConnexion = new DBConnexionAction();
    			dbConnexion.ouvrirConnexion();
     
    			// TRAITEMENT DES LANCES BARCOS DE FIERRO
    			ResultSet rsFierro = dbConnexion.getStmt().executeQuery(
    					"select DIA, NUMERO_LANCES from BIT_LANCES_FIERRO_DIA group by DIA,NUMERO_LANCES order by DIA");
     
    			// Boucle de traitement des enregistrements
    			while (rsFierro.next()) {
     
    				String jour = rsFierro.getString("DIA");
     
    				Date day = format.parse(jour);
     
    				DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.FRANCE).format(day);
     
    				String nombre = rsFierro.getString("NUMERO_LANCES");
    				dataset.addValue(new Double(nombre), serieFierro, day.toString());
    			}
     
    			// TRAITEMENT DES LANCES BARCOS DE ARRASTRE
    			ResultSet rsArrastre = dbConnexion.getStmt().executeQuery(
    					"select DIA, NUMERO_LANCES from BIT_LANCES_ARRASTRE_DIA group by DIA,NUMERO_LANCES order by DIA");
     
    			// Boucle de traitement des enregistrements
    			while (rsArrastre.next()) {
     
    				String jour = rsArrastre.getString("DIA");
     
    				Date day = format.parse(jour); 
    				String nombre = rsArrastre.getString("NUMERO_LANCES");
    				dataset.addValue(new Double(nombre), serieArrastre, day.toString());
    			}
     
    			// TRAITEMENT DES LANCES BARCOS DE MADERA
    			ResultSet rsMadera = dbConnexion.getStmt().executeQuery(
    					"select DIA, NUMERO_LANCES from BIT_LANCES_MADERA_DIA group by DIA,NUMERO_LANCES order by DIA");
     
    			// Boucle de traitement des enregistrements
    			while (rsMadera.next()) {
     
    				String jour = rsMadera.getString("DIA");
     
    				Date day = format.parse(jour); 
    				String nombre = rsMadera.getString("NUMERO_LANCES");
    				dataset.addValue(new Double(nombre), serieMadera, day.toString());
    			}
     
    			dbConnexion.fermerConnexion();
     
    		} catch (Exception e) {
    			throw e;}
     
    		return dataset;
    	}
     
    	public static String generateLineChart(HttpSession session, PrintWriter pw) {
    		String filename = null;
    		final CategoryDataset dataset;
    		try {
    			dataset = createDataset();
    			// create the chart...
    			final JFreeChart chart = ChartFactory.createLineChart(
    					"Numero de lances por dia", // chart title
    					"Dia", // domain axis label
    					"Numero de lance", // range axis label
    					dataset, // data
    					PlotOrientation.VERTICAL, // orientation
    					true, // include legend
    					true, // tooltips
    					false // urls
    					);
     
    			// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    			// final StandardLegend legend = (StandardLegend) chart.getLegend();
    			// legend.setDisplaySeriesShapes(true);
    			// legend.setShapeScaleX(1.5);
    			// legend.setShapeScaleY(1.5);
    			// legend.setDisplaySeriesLines(true);
     
    			chart.setBackgroundPaint(Color.white);
     
    			final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    			plot.setBackgroundPaint(Color.lightGray);
    			plot.setRangeGridlinePaint(Color.white);
     
    			// customise the range axis...
    			final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    			rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    			rangeAxis.setAutoRangeIncludesZero(true);
     
    			// ****************************************************************************
    			// * 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. *
    			// ****************************************************************************
     
    			// customise the renderer...
    			final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot
    					.getRenderer();
    			// renderer.setDrawShapes(true);
     
    			renderer.setSeriesStroke(0, new BasicStroke(2.0f,
    					BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
    					new float[] { 10.0f, 6.0f }, 0.0f));
    			renderer.setSeriesStroke(1, new BasicStroke(2.0f,
    					BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
    					new float[] { 6.0f, 6.0f }, 0.0f));
    			renderer.setSeriesStroke(2, new BasicStroke(2.0f,
    					BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
    					new float[] { 2.0f, 6.0f }, 0.0f));
     
    			ChartRenderingInfo info = new ChartRenderingInfo(
    					new StandardEntityCollection());
     
    			filename = ServletUtilities.saveChartAsPNG(chart, 1000, 600, info,
    					session);
     
    			ChartUtilities.writeImageMap(pw, filename, info, true);
    			pw.flush();
     
    		} catch (Exception e) {
     
    		}
    		return filename;
     
    	}
    }
    Images attachées Images attachées  

Discussions similaires

  1. [Neural Network] Prédiction Séries Temporelles
    Par Laura Fish dans le forum MATLAB
    Réponses: 0
    Dernier message: 02/09/2011, 17h40
  2. séries temporelles - ARIMA
    Par mathieu_r dans le forum R
    Réponses: 5
    Dernier message: 21/04/2011, 16h23
  3. Réponses: 2
    Dernier message: 30/03/2010, 16h27
  4. Requète sur séries temporelles
    Par Christian78 dans le forum Requêtes et SQL.
    Réponses: 1
    Dernier message: 13/09/2008, 07h51
  5. Séries temporelles Arma et Farima
    Par sam13 dans le forum MATLAB
    Réponses: 1
    Dernier message: 31/01/2007, 19h19

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