I created a dynamic time series chart using JFreeChart API. and it is working fine. I have to add a combo box to it, in which time values will be there like 5 sec, 15 sec, 30 sec. when user choose on from it the time axis has to repaint with given interval and the timer has to delay the process for 5, 15,30 seconds(updating the chart). I this on my previous post this
with some extensions like adding combo box to it
but it's not worked for me, any help will be appreciated. thanks
EDIT 1 removed unwanted code and remaining code is
final DynamicTimeSeriesCollection dataset =
new DynamicTimeSeriesCollection(1, 60, new Second());
dataset.setTimeBase(new Second( 0,seriesvalue*2, 5, 11, 7, 2012));
dataset.addSeries(new float[]{0}, 0, "Currency Rate");
JFreeChart chart = createChart(dataset);
chartPanel = new ChartPanel(chart);
final JComboBox combo = new JComboBox();
combo.addItem("5");
combo.addItem("15");
combo.addItem("30");
combo.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if("5".equals(combo.getSelectedItem())){
seriesvalue=5;
timer.setDelay(seriesvalue*1000);
}else if("15".equals(combo.getSelectedItem())){
seriesvalue=15;
timer.setDelay(seriesvalue*1024);
unit=new DateTickUnit(DateTickUnitType.MINUTE,seriesvalue);
chartPanel.repaint();
}
}
});
add(chartPanel,BorderLayout.CENTER);
add(combo,BorderLayout.SOUTH);
timer = new Timer(999*seriesvalue, new ActionListener() {
public void actionPerformed(ActionEvent e) {
for(int i=0;i<seriesvalue;i++){
newData[0] = randy.getRandomvalue();
dataset.advanceTime();
dataset.appendData(newData);
}
}
});
create dataset code
private JFreeChart createChart(final XYDataset dataset) {
JFreeChart result= ChartFactory.createTimeSeriesChart(
"Dyanmic chart", "hh:mm:ss", "Currency", dataset, true, true, false);
final XYPlot plot = result.getXYPlot();
dateAxis= (DateAxis)plot.getDomainAxis();
unit = new DateTickUnit(DateTickUnitType.MINUTE,seriesvalue/2);
return result;
}
main method
public static void main(final String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
DynaChart chart = new DynaChart();
chart.pack();
RefineryUtilities.centerFrameOnScreen(chart);
chart.setVisible(true);
chart.start();
}
});
}
TimeSeriesCollection
orDynamicTimeSeriesCollection
? Please edit your question to include an sscce that shows your approach. – trashgod