Please help.

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Shirley

Please help.

Post by Shirley » Tue Jan 28, 2003 10:54 pm

Here are some sample segment of codes.
I just want to add a point to the XY Graph
every time click the button.
But it won't work!
What is missing?
Could you help me?
class appendingXY extends XYSeriesCollection
{
static int count=1;
public appendingXY(XYSeries series) {
super ( series );
}

public void addNew () {
getSeries(0).add(90.0*i, 10.0);
notifyListeners(new DatasetChangeEvent(this, this));
}
};
... ...

XYDataset xyDataset;

... ...

JButton jb = new JButton("Change" );
jb.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println ("actionPerformed");
((appendingXY)xyDataset).addNew();
}
} );

David Gilbert

Re: Please help.

Post by David Gilbert » Wed Jan 29, 2003 12:14 am

Hi Shirley,

Try out the DynamicDataDemo application in the src/com/jrefinery/chart/demo directory in the distribution. It displays a timeseries that has a new value added each time the user clicks a button.

Regards,

Dave Gilbert

Shirley

Re: Please help.

Post by Shirley » Wed Jan 29, 2003 1:24 am

Thanks Dave.
I just found out the reason of the chart not
updating.
But when should you use the graph as a JLabel?
Shirley
Here is what I did:
***
JLabel lblChart = new JLabel();
lblChart.setHorizontalAlignment(JLabel.CENTER);
lblChart.setVerticalAlignment(JLabel.CENTER);
lblChart.setIcon(new ImageIcon(image));

this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(lblChart, BorderLayout.CENTER);
this.setSize(600,400);
this.setVisible(true);
***
The real chart object is not displayed.

Locked