[JFreeChart] Mettre image de fond pour un graphe
Bonjour,
J'ai conçu un histogramme tout simple :
Code:
1 2 3 4 5 6 7 8 9 10
|
DefaultCategoryDataset bars = new DefaultCategoryDataset();
bars.setValue(6, "Profit", "Jane");
bars.setValue(7, "Profit", "Tom");
bars.setValue(8, "Profit", "Jill");
bars.setValue(5, "Profit", "John");
bars.setValue(12, "Profit", "Fred");
JFreeChart chart3 = ChartFactory.createBarChart("Comparison between Salesman",
"", "", bars, PlotOrientation.HORIZONTAL,
false, false, false); |
(il marche, il provient d'un autre tuto)
Maintenant j'aimerais sélectionner une image déjà existante sur ma machine pour la mettre en image de fond au lieu du gris habituel. Je sais que c'est possible mais je n'ai pas compris comment.
Il y a bien chart3.setBackgroundImage(image) mais je n'ai pas compris comment déclarer l'image en question.
Pour insérer l'image j'ai testé :
Code:
1 2 3
|
import java.awt.image.BufferedImage;
BufferedImage image = ImageIO.read("D:\\Mes Data\\StageM2\\Workspace\\Graphes\\fond rouge.png"); |
mais il ne semble pas prendre une url...
J'ai testé :
Code:
1 2 3 4 5
|
java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
Image fond_rouge = toolkit.getImage("D:\\fond rouge.png");
// dans le code de l'histogramme :
chart3.setBackgroundImage(fond_rouge); |
mais le fond reste gris.
Quelqu'un saurait me renseigner sur les librairies et les commandes à utiliser ?
Voilà !