我有一个动态区域图表,用w鼠标滚轮监听器将数据放在我的图表上的时间,我想设置我的域轴10秒只因为我的图表从头开始显示所有数据但我想要只显示最后10秒。 怎么做? 这是我的代码:
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();