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

SWT/JFace Java Discussion :

Problème avec JFreeChart dans RCP


Sujet :

SWT/JFace Java

  1. #1
    Membre averti
    Inscrit en
    Février 2003
    Messages
    51
    Détails du profil
    Informations forums :
    Inscription : Février 2003
    Messages : 51
    Par défaut Problème avec JFreeChart dans RCP
    Bonjour à tous...

    Je développe un soft avec RCP et j'ai bien tenté d'y intégrer un composant JFreeChart mais ca me plante à la gueule...

    Alors pour tester, j'ai créer un nouveau projet tout simple avec une vue dans laquelle je souhaite afficher un composant JFreeChart et là pareil...

    Voila ce que ca donne : VOIR L'IMAGE

    L'erreur est simple :
    java.lang.NoClassDefFoundError: org/jfree/data/general/DefaultPieDataset
    Or je pense avoir correctement référencé toutes mes librairies ".jar"... enfin je crois :S

    J'ai pourtant appliqué ce que j'ai pu lire à cette adresse à la lettre :
    http://www.vogella.de/articles/Eclip...t/article.html

    Et je ne comprends vraiment pas...
    En ce qui concerne les versions, j'ai pris JCommon 1.0.12 et JFreeChart 1.0.9 (normal, experimental et swt).
    Tout ca pour essayer de faire un camembert...

    J'en appelle donc à vos connaissances pour m'aider à avancer un peu...
    Si vous avez besoin d'infos complémentaires, n'hésitez pas... je vous file même le code (c'est le même quasiment que sur le site) :

    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
    package diagramtest;
     
    import java.awt.Font;
     
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.ui.part.ViewPart;
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.plot.PiePlot;
    import org.jfree.data.general.DefaultPieDataset;
    import org.jfree.data.general.PieDataset;
    import org.jfree.experimental.chart.swt.ChartComposite;
     
    public class VueGraphic extends ViewPart {
     
    	public VueGraphic() {
    		// TODO Auto-generated constructor stub
    	}
     
    	private static PieDataset createDataset() {
    		DefaultPieDataset dataset = new DefaultPieDataset();
    		dataset.setValue("One", new Double(43.2));
    		dataset.setValue("Two", new Double(10.0));
    		dataset.setValue("Three", new Double(27.5));
    		dataset.setValue("Four", new Double(17.5));
    		dataset.setValue("Five", new Double(11.0));
    		dataset.setValue("Six", new Double(19.4));
    		return dataset;
    	}
     
    	private static JFreeChart createChart(PieDataset dataset) {
     
    		JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 1", // chart
    				// title
    				dataset, // data
    				true, // include legend
    				true, false);
     
    		PiePlot plot = (PiePlot) chart.getPlot();
    		plot.setSectionOutlinesVisible(false);
    		plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    		plot.setNoDataMessage("No data available");
    		plot.setCircular(false);
    		plot.setLabelGap(0.02);
    		return chart;
     
    	}
     
    	@Override
    	public void createPartControl(Composite parent) {
    		// TODO Auto-generated method stub
    //		Text text = new Text(parent, SWT.BORDER);
    //		text.setText("Imagine a fantastic user interface here");
     
    		JFreeChart chart = createChart(createDataset());
    		final ChartComposite frame = new ChartComposite(parent, SWT.NONE,
    				chart, true);
     
    	}
     
    	@Override
    	public void setFocus() {
    		// TODO Auto-generated method stub
     
    	}
     
     
    }
    Comme vous pouvez le voir, j'ai référencé les JAR comme des librairies utilisateurs... J'ai également tenté de faire un import d'EXTERNAL JARS et ca change rien...

    Voila...

    Merci beaucoup à tous par avance !!

    ++

  2. #2
    Nouveau candidat au Club
    Profil pro
    Inscrit en
    Février 2008
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 2
    Par défaut RCP - JFreeChart
    Salut !

    Tout d'abord, je n'ai jamais intégré JFreeChart avec Eclipse RCP. Mais bon, il n'y a pas de raison ... le truc, c'est que visiblement, tu as bien jfreechart dans ton classpath pour lacompilation, mais pas pour l'exécution. Dans ton plugin (c'est bien un plugin que tu fais ? ce peut être une vue, une perspective, ...), tu dois avoir un dossier lib ou un truc comme ça. S'il s'agit bien d'un plugin, il me semble que dans le xml de conf de ton plugin, tu lui donnes les dépendances (jars, ...). C'est là que tu dois ajouter jfreechart ...

    bonne chance

    Merci pour ton MP et donc ta confiance ...

    Sur le site d'eclipse, tu dois avoir des infos là dessus

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    258
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 258
    Par défaut
    Bonjour, ce sujet m'interesse car dans le cadre d'une de mes applications je dois utiliser des graphiques. J'ai donc choisi comme toi JFreeChart.
    Je viens de tester l'exemple que tu mentionne et ça marche nickel.

    Cela ne réponds pas à ta question alors, j'ai téléchargé la dernière version de JFreeChart 1.0.9. J'ai ensuite copié les jar suivants dans le répertoire lib de mon appli RCP:
    jfreechart-1.0.9.jar
    jfreechart-1.0.9-experimental.jar
    jcommon-1.0.12.jar
    jfreechart-1.0.9-swt.jar
    swtgraphics2d.jar

    Et ensuite tu ouvre le fichier plugin.xml de ton projet RCP.
    Dans l'onglet Runtime tu clique sur Add dans la frame ClassPath et tu ajoute les jar précédent.

    Et voilà.

  4. #4
    Membre averti
    Inscrit en
    Février 2003
    Messages
    51
    Détails du profil
    Informations forums :
    Inscription : Février 2003
    Messages : 51
    Par défaut
    Merci pour votre aide...

    Effectivement les jar étaient mal rattachés ce qui fait que ca compilait mais ca ne s'exécutait pas comme il le fallait...

    Aprés maintes manipulations plus ou moins sioux, j'ai fini par réussir à les rattacher comme il le fallait au projet... mais autant vous dire que le comportement de RCP est assez particulier... il ne suffit pas de les ajouter au projet en EXTERNAL JARS mais il faut également aller le spécifier dans le plugin.xml...

    Merci encore

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Février 2008
    Messages
    46
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 46
    Par défaut
    Bonjour à vous,

    Je suis tombé sur ce post aprés deja beaucoup de recherches...

    J'ai la même erreur :
    java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset

    sauf que je compile mon appli en ligne de commande...

    j'ai bien le
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    import org.jfree.data.general.PieDataset;
    je compile avec:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    javac -classpath ./lib/jfreechart-1.0.13.jar:./jcommon-1.0.16.jar Test.java
    le programme compile sans erreur

    mais à l'execution il me sort l'erreur:
    java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset

    qu'ai je oublier????

    Merci d'avance pour vos reponses.

  6. #6
    Expert confirmé
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Par défaut
    Bah il faut aussi utiliser le -classpath pour la commande java (ou renseigner l'attribut classpath de ton manifest si ton appli est contenue dans un jar).

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Février 2008
    Messages
    46
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 46
    Par défaut
    Salutations Sinok et merci de me répondre!

    je me permet de linker mon code ainsi que les erreurs obtenues a l'execution au cas ou tu pourrais m'aider d'avantage car ca ne fonctionne toujours pas

    le 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
     
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.awt.image.BufferedImage;
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.plot.PiePlot;
    import org.jfree.data.general.DefaultPieDataset;
    import org.jfree.data.general.PieDataset;
     
    public class Test extends JPanel{
     
    	public JLabel lblChart;
     
    	Test(){
    		super(new FlowLayout());
     
    		//test de pie chart avec JfreeChart
    		DefaultPieDataset pieDataset = new DefaultPieDataset();
    		pieDataset.setValue("JavaWorld", new Integer(75));
    		pieDataset.setValue("Other", new Integer(25));
     
    		JFreeChart chart = ChartFactory.createPieChart("Sample Pie Chart", pieDataset, true, false,	false);	
     
    		BufferedImage image = chart.createBufferedImage(500,300);
     
    		lblChart = new JLabel();
    		lblChart.setIcon(new ImageIcon(image));
     
    		this.add(lblChart);
            this.setPreferredSize(new Dimension(400, 550));
            this.setBackground(Color.PINK);
     
    	}//constructor
     
    	private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("test");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
            //Create and set up the content pane.
            JComponent test = new Test();
            test.setOpaque(true); //content panes must be opaque
            frame.setLocation(500,300);
            frame.setContentPane(test);
            frame.setResizable(true);
     
            //Display the window.
            frame.pack();
            frame.setVisible(true);
     
        }//createAndShowGUI
     
    	public static void main(String[] args) {
    	    //Schedule a job for the event-dispatching thread:
    	    //creating and showing this application's GUI.
    	    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    		    public void run() {
    		    	createAndShowGUI();
    		    }
    		});
    	}
     
    }
    il y a vraiment le strict minimum:
    Test est donc un JPanel auquel j'ajoute un JLabel contenant la JChart (méthode donnée dans le tutorial de JFreeChart http://www.javaresources.biz/jfreechart_tutorial.jsp)

    ---> la compile avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    javac -classpath ./jfreechart-1.0.9.jar Test.java
    passe bien

    pour l'execution j'ai essayé 2 choses:
    me renvoie Exception in thread "main" java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset

    ET
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     java -classpath ./jfreechart-1.0.9.jar Test
    qui me renvoie Exception in thread "main" java.lang.NoClassDefFoundError: Test

    personnelement j'etais convaincu qu'on ne devait plus utiliser le -classpath lors de l'execution mais bon, j'ai essayé les deux et les deux ne marchent pas...

    Je précise que si j'enleve le code de la pieChart l'appli se lance et ouvre une fenetre sans lancer d'erreur...

    Si vous pouviez m'aider SVP parceque la le code étant on ne peut plus minimaliste je ne vois pas ou je me suis planté...

    MERCI d'avance

  8. #8
    Expert confirmé
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Par défaut
    Il faut ajouter le répertoire courant au classpath, sinon java ne trouvera pas ta classe (ce qui est somme toute fort normal).

    Donc:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    java -classpath ./jfreechart-1.0.9.jar;. Test
    Devrait faire l'affaire

  9. #9
    Membre averti
    Profil pro
    Inscrit en
    Février 2008
    Messages
    46
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 46
    Par défaut
    Citation Envoyé par sinok Voir le message
    Il faut ajouter le répertoire courant au classpath, sinon java ne trouvera pas ta classe (ce qui est somme toute fort normal).

    Donc:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    java -classpath ./jfreechart-1.0.9.jar;. Test
    Devrait faire l'affaire
    je ne comprend pas la présence du ";." dans la ligne de commande?
    d'ailleurs quand j'essai il me dit que la commande n'est tout simplement pas valide...

    par contre,
    quand tu dis d'ajouter le rep courant au classpath, c'est deja fait puisque quand j'enleve le code utilisant Jfreechart l'appli se lance, non?

    ou alors je n'ai pas compris ou tu voulais en venir?

    désolé pour ma "Noobitude" ^^

  10. #10
    Expert confirmé
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Par défaut
    Sous quel système es tu? (si tu es sous un UNIX-like comme Linux ou MacOs, il faut utiliser :. et non ;. qui est le séparateur de path Windows)

    Ensuite pour l'histoire du répertoire courant, il faut comprendre que lorsque l'on ne précise pas le classpath, la JVM prend le sette par défaut au répertoire courant. Toutefois, dès que l'on utilise l'option -cp (ou -classpath, ce sont les mêmes), elle utilise comme classpath ce qui lui est fourni par cette option, et non plus le répertoire courant (dans certains cas il est inutile d'avoir le répertoire courant dans le classpath)...

  11. #11
    Membre averti
    Profil pro
    Inscrit en
    Février 2008
    Messages
    46
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 46
    Par défaut
    Oui je suis sous Linux ^^ (j'avais oublié de le préciser^^)

    entre temps j'ai résolu le probleme avec un fichier build.xml et ai fait de mon appli un jar exécutable. (j'ai aussi changé de librairie, je suis parti sur Chart2D).

    d'ailleurs j'en profite pour demander (on ne sait jamais) s'il existe une version de "JMSL Chart" gratuite? c'est la librairie de graphisme la plus simple d'utilisation que j'ai pu trouver cependant je n'ai trouvé que la version payante...

    ou alors si vous connaissez une autre librairie simple et gratuite?

    En tout cas, je prend bonnes notes de tes conseils que je ne manquerais pas d'utiliser sous peu!

    Merci bien.

  12. #12
    Invité de passage
    Homme Profil pro
    Élevé Ingénieur
    Inscrit en
    Avril 2011
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Élevé Ingénieur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2011
    Messages : 1
    Par défaut Une erreur de compilation
    Bonjour,

    Je me permets d'écrire dans ce forum, car je rencontre un problème que je ne comprends pas. Je suis débutant en Java et je dois faire des représentations graphiques en utilisant
    JFreechart, mais j'obtiens des erreurs lors de la compilation :

    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
     
     
    Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems: 
     
    	The method createXYLineChart(String, String, String, XYDataset, PlotOrientation, boolean, boolean, boolean) in the type ChartFactory is not applicable for the arguments (String, String, String, XYDataset, PlotOrientation, boolean, boolean, boolean)
     
    	The constructor XYLineAndShapeRenderer(boolean, boolean) is undefined
     
    	The method setRenderer(XYItemRenderer) in the type XYPlot is not applicable for the arguments (XYLineAndShapeRenderer)
     
    	The method setBaseShapesVisible(boolean) is undefined for the type XYLineAndShapeRenderer
     
    	The method setBaseShapesFilled(boolean) is undefined for the type XYLineAndShapeRenderer
     
    	The constructor StandardXYItemLabelGenerator(String, NumberFormat, NumberFormat) is undefined
     
    	The method setBaseItemLabelGenerator(XYItemLabelGenerator) is undefined for the type XYLineAndShapeRenderer
     
     
    	at chart.JFreeChartDemo.createChart(JFreeChartDemo.java:93)
    	at chart.JFreeChartDemo.<init>(JFreeChartDemo.java:47)
    	at chart.Main$1.run(Main.java:47)
    	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
     
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Le code utilisé est le suivant( j'ai trouvé ce code sur internet ) :

    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
     
     
    package chart;
     
     
    import org.jfree.data.xy.*;
    import java.awt.BasicStroke;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.EventQueue;
    import java.awt.Stroke;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.text.NumberFormat;
    import java.util.Random;
    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.NumberAxis;
    import org.jfree.chart.axis.TickUnitSource;
    import org.jfree.chart.labels.StandardXYItemLabelGenerator;
    import org.jfree.chart.labels.XYItemLabelGenerator;
    import org.jfree.chart.plot.PlotOrientation;
    import org.jfree.chart.plot.XYPlot;
    import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
    import org.jfree.data.xy.DefaultXYDataset;
    import org.jfree.data.xy.XYDataset;
    import org.jfree.ui.RefineryUtilities;
     
    public class JFreeChartDemo extends JFrame {
     
    	 private static final int MAX = 8;
    	    private static final Random random = new Random();
     
    	    public JFreeChartDemo(String title)
    	    {
    	        super(title);
    	        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
    	        final DefaultXYDataset dataset = new DefaultXYDataset();
     
    	        dataset.addSeries("Series0", createSeries(0));
    	        dataset.addSeries("Series1", createSeries(1));
     
    	        JFreeChart chart = createChart(dataset);
    	        ChartPanel chartPanel = new ChartPanel(chart, false);
    	        chartPanel.setPreferredSize(new Dimension(640, 480));
    	        this.add(chartPanel, BorderLayout.CENTER);
     
    	        JPanel buttonPanel = new JPanel();
    	        JButton addButton = new JButton("Add Series");
    	        buttonPanel.add(addButton);
    	        addButton.addActionListener(new ActionListener() {
    	            public void actionPerformed(ActionEvent e) {
    	                int n = dataset.getSeriesCount();
    	                dataset.addSeries("Series" + n, createSeries(n));
    	            }
    	        });
    	        JButton remButton = new JButton("Remove Series");
    	        buttonPanel.add(remButton);
    	        remButton.addActionListener(new ActionListener() {
    	            public void actionPerformed(ActionEvent e) {
    	                int n = dataset.getSeriesCount() - 1;
    	                dataset.removeSeries("Series" + n);
    	            }
    	        });
     
    	        this.add(buttonPanel, BorderLayout.SOUTH);
     
    	    }
     
     
    	    private double[][] createSeries(int mean)
    	    {
     
    	        double[][] series = new double[2][MAX];
    	        for (int i = 0; i < MAX; i++)
    	        {
    	            series[0][i] = (double) i;
    	            series[1][i] = mean + random.nextGaussian() / 2;
     
    	        }
    	        return series;
    	    }
     
     
     
    	    private  JFreeChart createChart(XYDataset dataset) {
     
    	        // create the chart...
    	        JFreeChart chart = ChartFactory.createXYLineChart(
    	            "Serial Data", // chart title
    	            "Domain", // domain axis label
    	            "Rannge", // range axis label
    	            dataset,  // initial series
    	            PlotOrientation.VERTICAL, // orientation
    	            true, // include legend
    	            true, // tooltips?
    	            false // URLs?
    	            );
     
    	        // set chart background
    	        chart.setBackgroundPaint(Color.white);
     
    	        // set a few custom plot features
    	        XYPlot plot = (XYPlot) chart.getPlot();
    	        plot.setBackgroundPaint(new Color(0xffffe0));
    	        plot.setDomainGridlinesVisible(true);
    	        plot.setDomainGridlinePaint(Color.lightGray);
    	        plot.setRangeGridlinePaint(Color.lightGray);
     
    	        // set the plot's axes to display integers
    	        TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
    	        NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    	        domain.setStandardTickUnits(ticks);
    	        NumberAxis range = (NumberAxis) plot.getRangeAxis();
    	        range.setStandardTickUnits(ticks);
     
     
    	        // render shapes and lines
    	        XYLineAndShapeRenderer renderer =
    	            new XYLineAndShapeRenderer(true, true);
    	        plot.setRenderer(renderer);
    	        renderer.setBaseShapesVisible(true);
    	        renderer.setBaseShapesFilled(true);
     
    	        // set the renderer's stroke
    	        Stroke stroke = new BasicStroke(
    	            3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
    	        renderer.setBaseOutlineStroke(stroke);
     
    	        // label the points
    	        NumberFormat format = NumberFormat.getNumberInstance();
    	        format.setMaximumFractionDigits(2);
    	        XYItemLabelGenerator generator =
    	            new StandardXYItemLabelGenerator(
    	                StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT,
    	                format, format);
    	        renderer.setBaseItemLabelGenerator(generator);
    	        renderer.setBaseItemLabelsVisible(true);
     
    	        return chart;
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    }
    }

    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
     
     et dans le main :
     
    public class Main {
     
    	/**
             * @param args
             */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
     
    		 EventQueue.invokeLater(new Runnable() {
     
    	            public void run() {
    	                JFreeChartDemo demo = new JFreeChartDemo("JFreeChartDemo");
    	                demo.pack();
    	                demo.setLocationRelativeTo(null);
    	                demo.setVisible(true);
    	            }
    	         });
     
     
     
    	}

  13. #13
    Membre averti
    Inscrit en
    Décembre 2010
    Messages
    36
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 36
    Par défaut
    bonjour a tous ,

    J'ai un problème avec JFreeChart et Tomcat.
    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
    <%@ page  import="java.awt.*" %>
    <%@ page  import="java.io.*" %>
    <%@ page  import="org.jfree.chart.*" %>
    <%@ page  import="org.jfree.chart.axis.*" %>
    <%@ page  import="org.jfree.chart.entity.*" %>
    <%@ page  import="org.jfree.chart.labels.*" %>
    <%@ page  import="org.jfree.chart.plot.*" %>
    <%@ page  import="org.jfree.chart.renderer.category.*" %>
    <%@ page  import="org.jfree.chart.urls.*" %>
    <%@ page  import="org.jfree.data.category.*" %>
    <%@ page  import="org.jfree.data.general.*" %>
     
    <%
      final double[][] data = new double[][]{
      {210, 300, 320, 265, 299},
      {200, 304, 201, 201, 340}
     };
     
      final CategoryDataset dataset = 
       DatasetUtilities.createCategoryDataset(
      "Team ", "", data);
     
      JFreeChart chart = null;
      BarRenderer renderer = null;
      CategoryPlot plot = null;
     
     
      final CategoryAxis categoryAxis = new CategoryAxis("Match");
      final ValueAxis valueAxis = new NumberAxis("Run");
      renderer = new BarRenderer();
     
      plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 
      renderer);
     
      plot.setOrientation(PlotOrientation.VERTICAL);
      chart = new JFreeChart("Srore Bord", JFreeChart.DEFAULT_TITLE_FONT, 
      plot, true);
     
      chart.setBackgroundPaint(new Color(249, 231, 236));
     
      Paint p1 = new GradientPaint(
     0.0f, 0.0f, new Color(16, 89, 172), 0.0f, 0.0f, new Color
       (201, 201, 244));
     
      renderer.setSeriesPaint(1, p1);
     
      Paint p2 = new GradientPaint(
      0.0f, 0.0f, new Color(255, 35, 35), 0.0f, 0.0f, new Color
       (255, 180, 180));
     
      renderer.setSeriesPaint(2, p2);
     
      plot.setRenderer(renderer);
     
      try {
      final ChartRenderingInfo info = new ChartRenderingInfo
       (new StandardEntityCollection());
     
     
     
     
     
      ChartUtilities.saveChartAsJPEG(new File("\\ftp.jpg"),chart,600,300);
      } catch (Exception e) {
     out.println(e);
      }
    %>
     
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <IMG SRC="ftp.png" WIDTH="600" 
      HEIGHT="400" BORDER="0" USEMAP="#chart">
      </body>
    </body>
    </html>
    au niveau d'execution avec tomcat il maffiche cette erreur
    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
     
     
    Une erreur s'est produite à la ligne: 21 dans le fichier jsp: /graph.jsp
    CategoryDataset cannot be resolved to a type
    18:   {200, 304, 201, 201, 340}
    19:  };
    20: 
    21:   final CategoryDataset dataset = 
    22:    DatasetUtilities.createCategoryDataset(
    23:   "Team ", "", data);
    24: 
     
     
    Une erreur s'est produite à la ligne: 22 dans le fichier jsp: /graph.jsp
    DatasetUtilities cannot be resolved
    19:  };
    20: 
    21:   final CategoryDataset dataset = 
    22:    DatasetUtilities.createCategoryDataset(
    23:   "Team ", "", data);
    24: 
    25:   JFreeChart chart = null;
     
     
    Une erreur s'est produite à la ligne: 25 dans le fichier jsp: /graph.jsp
    JFreeChart cannot be resolved to a type
    22:    DatasetUtilities.createCategoryDataset(
    23:   "Team ", "", data);
    24: 
    25:   JFreeChart chart = null;
    26:   BarRenderer renderer = null;
    27:   CategoryPlot plot = null;
    28: 
     
     
    Une erreur s'est produite à la ligne: 26 dans le fichier jsp: /graph.jsp
    BarRenderer cannot be resolved to a type
    23:   "Team ", "", data);
    24: 
    25:   JFreeChart chart = null;
    26:   BarRenderer renderer = null;
    27:   CategoryPlot plot = null;
    28: 
    29: 
     
     
    Une erreur s'est produite à la ligne: 27 dans le fichier jsp: /graph.jsp
    CategoryPlot cannot be resolved to a type
    24: 
    25:   JFreeChart chart = null;
    26:   BarRenderer renderer = null;
    27:   CategoryPlot plot = null;
    28: 
    29: 
    30:   final CategoryAxis categoryAxis = new CategoryAxis("Match");
     
     
    Une erreur s'est produite à la ligne: 30 dans le fichier jsp: /graph.jsp
    CategoryAxis cannot be resolved to a type
    27:   CategoryPlot plot = null;
    28: 
    29: 
    30:   final CategoryAxis categoryAxis = new CategoryAxis("Match");
    31:   final ValueAxis valueAxis = new NumberAxis("Run");
    32:   renderer = new BarRenderer();
    33: 
     
     
    Une erreur s'est produite à la ligne: 30 dans le fichier jsp: /graph.jsp
    CategoryAxis cannot be resolved to a type
    27:   CategoryPlot plot = null;
    28: 
    29: 
    30:   final CategoryAxis categoryAxis = new CategoryAxis("Match");
    31:   final ValueAxis valueAxis = new NumberAxis("Run");
    32:   renderer = new BarRenderer();
    33: 
     
     
    Une erreur s'est produite à la ligne: 31 dans le fichier jsp: /graph.jsp
    ValueAxis cannot be resolved to a type
    28: 
    29: 
    30:   final CategoryAxis categoryAxis = new CategoryAxis("Match");
    31:   final ValueAxis valueAxis = new NumberAxis("Run");
    32:   renderer = new BarRenderer();
    33: 
    34:   plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 
     
     
    Une erreur s'est produite à la ligne: 31 dans le fichier jsp: /graph.jsp
    NumberAxis cannot be resolved to a type
    28: 
    29: 
    30:   final CategoryAxis categoryAxis = new CategoryAxis("Match");
    31:   final ValueAxis valueAxis = new NumberAxis("Run");
    32:   renderer = new BarRenderer();
    33: 
    34:   plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 
     
     
    Une erreur s'est produite à la ligne: 32 dans le fichier jsp: /graph.jsp
    BarRenderer cannot be resolved to a type
    29: 
    30:   final CategoryAxis categoryAxis = new CategoryAxis("Match");
    31:   final ValueAxis valueAxis = new NumberAxis("Run");
    32:   renderer = new BarRenderer();
    33: 
    34:   plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 
    35:   renderer);
     
     
    Une erreur s'est produite à la ligne: 34 dans le fichier jsp: /graph.jsp
    CategoryPlot cannot be resolved to a type
    31:   final ValueAxis valueAxis = new NumberAxis("Run");
    32:   renderer = new BarRenderer();
    33: 
    34:   plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 
    35:   renderer);
    36: 
    37:   plot.setOrientation(PlotOrientation.VERTICAL);
     
     
    Une erreur s'est produite à la ligne: 37 dans le fichier jsp: /graph.jsp
    PlotOrientation.VERTICAL cannot be resolved to a type
    34:   plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 
    35:   renderer);
    36: 
    37:   plot.setOrientation(PlotOrientation.VERTICAL);
    38:   chart = new JFreeChart("Srore Bord", JFreeChart.DEFAULT_TITLE_FONT, 
    39:   plot, true);
    40: 
     
     
    Une erreur s'est produite à la ligne: 38 dans le fichier jsp: /graph.jsp
    JFreeChart cannot be resolved to a type
    35:   renderer);
    36: 
    37:   plot.setOrientation(PlotOrientation.VERTICAL);
    38:   chart = new JFreeChart("Srore Bord", JFreeChart.DEFAULT_TITLE_FONT, 
    39:   plot, true);
    40: 
    41:   chart.setBackgroundPaint(new Color(249, 231, 236));
     
     
    Une erreur s'est produite à la ligne: 38 dans le fichier jsp: /graph.jsp
    JFreeChart.DEFAULT_TITLE_FONT cannot be resolved to a type
    35:   renderer);
    36: 
    37:   plot.setOrientation(PlotOrientation.VERTICAL);
    38:   chart = new JFreeChart("Srore Bord", JFreeChart.DEFAULT_TITLE_FONT, 
    39:   plot, true);
    40: 
    41:   chart.setBackgroundPaint(new Color(249, 231, 236));
     
     
    Une erreur s'est produite à la ligne: 58 dans le fichier jsp: /graph.jsp
    ChartRenderingInfo cannot be resolved to a type
    55:   plot.setRenderer(renderer);
    56: 
    57:   try {
    58:   final ChartRenderingInfo info = new ChartRenderingInfo
    59:    (new StandardEntityCollection());
    60: 
    61: 
     
     
    Une erreur s'est produite à la ligne: 58 dans le fichier jsp: /graph.jsp
    ChartRenderingInfo cannot be resolved to a type
    55:   plot.setRenderer(renderer);
    56: 
    57:   try {
    58:   final ChartRenderingInfo info = new ChartRenderingInfo
    59:    (new StandardEntityCollection());
    60: 
    61: 
     
     
    Une erreur s'est produite à la ligne: 59 dans le fichier jsp: /graph.jsp
    StandardEntityCollection cannot be resolved to a type
    56: 
    57:   try {
    58:   final ChartRenderingInfo info = new ChartRenderingInfo
    59:    (new StandardEntityCollection());
    60: 
    61: 
    62: 	
     
     
    Une erreur s'est produite à la ligne: 65 dans le fichier jsp: /graph.jsp
    ChartUtilities cannot be resolved
    62: 	
    63: 
    64:   
    65:   ChartUtilities.saveChartAsJPEG(new File("\\ftp.jpg"),chart,600,300);
    66:   } catch (Exception e) {
    67:  out.println(e);
    68:   }
     
     
    Stacktrace:
    	at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
    	at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    	at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
    	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
    	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
    	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
    	at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
    	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    	at java.lang.Thread.run(Thread.java:636)
    Merci d'avance pour votre aide

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

Discussions similaires

  1. Faire des camemberts - Problème avec JFreeChart sous appli RCP
    Par cdryk dans le forum Eclipse Platform
    Réponses: 0
    Dernier message: 31/03/2008, 14h17
  2. [PL SQL] Problème avec 'case' dans une fonction
    Par divail dans le forum Oracle
    Réponses: 14
    Dernier message: 13/03/2006, 15h50
  3. Problème avec Between dans un code
    Par Sendo dans le forum Access
    Réponses: 4
    Dernier message: 02/10/2005, 18h44
  4. problème avec graphique dans état access
    Par petitmic dans le forum Access
    Réponses: 5
    Dernier message: 07/09/2005, 14h55
  5. Problème avec TNMSMTP dans une boucle.
    Par Orgied dans le forum Web & réseau
    Réponses: 3
    Dernier message: 07/04/2004, 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