J'essaie d'apprendre les particularités de jCharts dans le but de l'intégrer à mon projet en cours.

http://jcharts.krysalis.org/

Je commence à bien comprendre comment doivent être organisés les différents composants d'un graphe (titre, légendes, données...) mais j'ai un problème de rafraîchissement.

En effet, l'exemple ci-dessous dessine un graphe parfaitement, mais lorsque je retaille la fenêtre, le graphe disparaît et ne s'affiche plus.

Comment dois-je programmer la création d'un graphe, pour que celui-ci soit toujours affiché quand un utilisateur va bouger la fenêtre de mon programme ?

EXEMPLE jCharts :

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
// TEST DES GRAPHES BAR
 
import org.jCharts.axisChart.*;
import org.jCharts.test.*;
import org.jCharts.types.*;
import org.jCharts.chartData.*;
import org.jCharts.nonAxisChart.*;
import org.jCharts.properties.*;
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
public class SwingDemo2 extends JFrame
{
private JPanel panel;
 
//*******************************************************************************
public SwingDemo2() throws ChartDataException, PropertyException
  {
  initComponents();
  }
//********************************************************************************/
private void initComponents() throws ChartDataException, PropertyException
  {
  setTitle("Test SwingDemo 2");
  setSize( 600, 400 );
  panel=new JPanel( true ); // construit un panel qui est DoubbleBuffered
  panel.setSize( 600, 400 );
  panel.setBackground(Color.yellow);
  getContentPane().add( panel );
  setVisible( true );
 
  // --------------------------------------------------------------------------------
  String[] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" };
  String xAxisTitle= "Années";
  String yAxisTitle= "Problèmes";
  String title= "Succès dans l'étude de JAVA";
  DataSeries dataSeries = new DataSeries( xAxisLabels,
                                          xAxisTitle,
                                          yAxisTitle,
                                          title );
 
  double[][] data= new double[][]{ { 250, 45, -36, 66, 145, 80, 55  } };
  String[] legendLabels= { "Réussite" };
  Paint[] paints= TestDataGenerator.getRandomPaints( 1 );
  BarChartProperties barChartProperties= new BarChartProperties();
  AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data,
                                                           legendLabels,
                                                           paints,
                                                           ChartType.BAR,
                                                           barChartProperties );
  dataSeries.addIAxisPlotDataSet( axisChartDataSet );
 
  ChartProperties chartProperties= new ChartProperties();
  AxisProperties axisProperties= new AxisProperties();
  LegendProperties legendProperties= new LegendProperties();
  AxisChart axisChart= new AxisChart( dataSeries,
                                      chartProperties,
                                      axisProperties,
                                      legendProperties,
                                      500,
                                      350 );
 
  axisChart.setGraphics2D( (Graphics2D) panel.getGraphics() );
  axisChart.render();
 
  addWindowListener( new WindowAdapter()
           {
           public void windowClosing( WindowEvent e )
              {
              exitForm( e );
              }
           }
        );
  }
// **********************************************************************************
  private void exitForm( WindowEvent windowEvent )
  {
    System.exit( 0 );
  }
//***********************************************************
  public static void main( String args[] ) throws ChartDataException, PropertyException
  {
  new SwingDemo2();
  }
}