Reputation: 465
I have a dynamic area chart which is implemented with w mouse wheel listener tu put data on my chart through the time, I want to set my domain axis for 10 seconds only because my chart is showin all data from the beginning but I want to display only the 10 last seconds. How to do that? Here's my code:
final XYSeries series = new XYSeries("Data");
XYSeriesCollection dataset = new XYSeriesCollection(series);
// Creation du area chart
JFreeChart chart = ChartFactory.createXYAreaChart("Fun Meter", "", "",
dataset, PlotOrientation.VERTICAL, false, false, false);
final JLabel a = new JLabel();
// Un chartpanel pour contenir le area chart
ChartPanel CP = new ChartPanel(chart);
// creation d'objet plot pour ajustement de tout ce qui est graphique
XYPlot xyPlot = (XYPlot) chart.getPlot();
// la couleur degradée pour le remplissage du area chart
GradientPaint gp0 = new GradientPaint(0.0f, 100.0f, new Color(50, 205,
50), 0.0f, 100.0f, Color.red);
xyPlot.getRenderer().setSeriesPaint(0, gp0);
xyPlot.setBackgroundPaint(Color.black);
xyPlot.setForegroundAlpha(0.75f);
GradientPaint gp1 = new GradientPaint(0.0f, 100.0f, Color.black, 0.0f,
1000.0f, new Color(153, 153, 153));
chart.setBackgroundPaint(gp1);
CP.addMouseWheelListener(new MouseWheelListener() {
public void mouseWheelMoved(MouseWheelEvent e) {
Integer rx = e.getWheelRotation();
Wheel = Wheel - rx;
}
});
new Timer(100, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
series.add(series.getItemCount(), Wheel);
}
}).start();
Upvotes: 0
Views: 236
Reputation: 205785
One approach is to use a DynamicTimeSeriesCollection
, shown here. The nMoments
constructor parameter specifies the number of TimePeriod
units to be retained.
Upvotes: 1