问题
Please, how can I update the Series of the JfreeChart.
My Jfreechart works like this,
I have a set of CheckBox, when I select the checkboxes from which I want to retrieve informations I would like to see them on the series zone of my graph.
The Series list are changing but there are not showing. How can do it inside the code ?
thanks
Edit
This is how my code is written
public DrawChart(JPanel panel){
this.refresh = new RefreshGraph();
this.displayChart (panel);
}
private void displayChart(JPanel jpanel){
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
Timer timer = new Timer(1000, new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
refresh.getRefresh (dataset);
}
});
timer.start ();
JFreeChart chart = createChart(dataset);
ChartPanel panel=new ChartPanel(chart);
panel.setPreferredSize (new Dimension(700,300));
jpanel.setLayout(new java.awt.BorderLayout());
jpanel.add (panel, BorderLayout.CENTER);
jpanel.repaint ();
jpanel.setVisible(true);
}
private JFreeChart createChart(final CategoryDataset dataset){
final JFreeChart result = ChartFactory.createLineChart ("", null, null, dataset, PlotOrientation.VERTICAL, true, true, false);
return result;
}
and this is how I fill the dataset
dataset.addValue (Double.parseDouble (separateValues[0]), _listSeries.get (0), aLine);
dataset.addValue (Double.parseDouble (separateValues[1]), _listSeries.get (1), aLine);
What I need is that , when the Timer is running every 1 second, the _listSeries (which represents the list of all the series to be displayed) also change. Only the values in the graph are changing no the Series zone.
How can I do it?
I was thinking to refresh the panel by calling repaint() but no way. it does not work.
Thanks
来源:https://stackoverflow.com/questions/11869704/jfreechart-dynamically-change-the-series-list