sam
sam

Reputation: 661

How to update a chart in JFreeChart?

I have a combinedXYPlot and a drop-down list. I want to update my chart based on user input from drop-down. How to do this? I tried the following code

frmJPanel.getContentPane().removeAll();

frmJPanel.setLayout(new BorderLayout());

initChart(option);

frmJPanel.repaint();

The changes are reflected only after I minimize/ maximize the window. What is the function that needs to be called? What is the better way to do this ?

Upvotes: 1

Views: 15659

Answers (2)

trashgod
trashgod

Reputation: 205785

ChartPanel "registers with the chart to receive notification of changes to any component of the chart. The chart is redrawn automatically whenever this notification is received." There are examples here and here.

Upvotes: 1

Joachim H. Skeie
Joachim H. Skeie

Reputation: 1903

I have my chart inside a org.jfree.chart.ChartPanel. When I want to update the chart I simply call on the chartPanel.repaint() method.

The chartPanel itself is added another JPanel, which in turn is placed in the main layout of the application.

Upvotes: 1

Related Questions