Olá, estou desenvolvendo um programa onde nele terá uma tela com um gráfico, estou utilizando o “JFreeChart” para a criação do gráfico, vi esse víedeo no YouTube para a criação do gráfico, porém ao compilar, ele não mostra o gráfico, fica tudo branco, veja abaixo o código completo da tela:
1 package telas;
2
3 import java.awt.EventQueue;
4 import javax.swing.JInternalFrame;
5 import org.jfree.chart.ChartFactory;
6 import org.jfree.chart.ChartPanel;
7 import org.jfree.chart.JFreeChart;
8 import org.jfree.chart.plot.PlotOrientation;
9 import org.jfree.data.category.DefaultCategoryDataset;
10 import javax.swing.event.InternalFrameAdapter;
11 import javax.swing.event.InternalFrameEvent;
12
13 public class Estatisticas extends JInternalFrame {
14
15 private static final long serialVersionUID = 1L;
16
17 public void TGrafico() {
18 // cria o conjunto de dados
19 DefaultCategoryDataset barra = new DefaultCategoryDataset();
20 barra.addValue(40, "maximo", "dia 1");
21 barra.addValue(38, "maximo", "dia 2");
22 barra.addValue(37, "maximo", "dia 3");
23 barra.addValue(31, "maximo", "dia 4");
24 barra.addValue(35, "maximo", "dia 5");
25 barra.addValue(42, "maximo", "dia 6");
26
27 // cria o gráfico
28 JFreeChart grafico = ChartFactory.createLineChart("Meu Grafico", "Dia", "Valor", barra, PlotOrientation.VERTICAL, true, true, false);
29 ChartPanel painel = new ChartPanel(grafico);
30 add(painel);
31 }
32 /**
33 * Launch the application.
34 */
35 public static void main(String[] args) {
36 EventQueue.invokeLater(new Runnable() {
37 public void run() {
38 try {
39 Estatisticas frame = new Estatisticas();
40 frame.setVisible(true);
41 } catch (Exception e) {
42 e.printStackTrace();
43 }
44 }
45 });
46 }
47
48 /**
49 * Create the frame.
50 */
51 public Estatisticas() {
52 setBounds(-5, -28, 805, 600);
53 getContentPane().setLayout(null);
54
55 addInternalFrameListener(new InternalFrameAdapter() {
56 public void internalFrameOpened(InternalFrameEvent arg0) {
57 TGrafico();
58 }
59 });
60
61 }
62 }