Archivo PNG generado
package jfree;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
public class BarChart {
public static void main(String[] args) throws IOException {
// TODO code application logic here
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.setValue(5, "jalados", "José");
dataset.setValue(5, "jalados", "Ronny");
dataset.setValue(4, "jalados", "Frank");
dataset.setValue(2, "jalados", "Sumire");
dataset.setValue(0, "jalados", "Maribel");
dataset.setValue(-1, "jalados", "Ian");
dataset.setValue(10, "aprobados", "José");
dataset.setValue(9, "aprobados", "Ronny");
dataset.setValue(12, "aprobados", "Frank");
dataset.setValue(13, "aprobados", "Sumire");
dataset.setValue(15, "aprobados", "Maribel");
dataset.setValue(12, "aprobados", "Ian");
JFreeChart chart = ChartFactory.createBarChart3D("Nivel de ignorancia",
"Estudiantes", "Cursos jalados",
dataset, PlotOrientation.VERTICAL, true, true, false);
BufferedImage img = ImageIO.read(new File("src/img/cars.jpg"));
chart.setBackgroundImage(img);
CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundImage(img);
BarRenderer render = (BarRenderer)plot.getRenderer();
render.setSeriesPaint(0, Color.darkGray);
render.setSeriesPaint(1, Color.LIGHT_GRAY);
chart.setBackgroundPaint(Color.RED);
try{
ChartUtilities.saveChartAsPNG(new File("C:\\barras.png"), chart, 500, 400);
}
catch(IOException e){
System.out.println("Error al crear el archivo");
}
ChartFrame frame = new ChartFrame("Gráfico de Barras", chart);
frame.pack();
frame.setVisible(true);
}
}
Espero te haya ayudado este tutorial, visita mi nuevo proyecto Test de Velocidad en el Teclado http://clubtyping.com/es