图形会在一段时间内缩小。我希望图表是动态的,并且必须为30秒跨度。 0-30sec,30-60sec ....我正在通过串行端口读取传感器数据。
JFreeChart chart = ChartFactory.createXYLineChart("Water Sensor Readings", "Serial no", "CM", dataset);
ChartPanel chartpanel =new ChartPanel(chart);
chartpanel.setPreferredSize(new java.awt.Dimension(1200,400));
XYPlot plot = (XYPlot) chart.getPlot();
NumberAxis domainAxis = new NumberAxis();
NumberAxis rangeAxis = new NumberAxis();
domainAxis.setAutoRange(false);
domainAxis.setLowerBound(0);
domainAxis.setTickUnit(new NumberTickUnit(2));
rangeAxis.setRange(0, 1000);
rangeAxis.setTickUnit(new NumberTickUnit(50));
plot.setRangeAxis(rangeAxis);
JScrollPane sc=new JScrollPane(chartpanel);
topPanel.add(sc);
window.setContentPane(topPanel);
@Override public void run()
{
Scanner scanner = new Scanner(chosenPort.getInputStream());
while(scanner.hasNextLine())
{
try
{
String line = scanner.nextLine();
x1=line.substring(1,6);
y=line.substring(7,12);
z=line.substring(13,18);
series.add(Double.parseDouble(x1),Double.parseDouble(z)*10);
series1.add(Double.parseDouble(x1),Double.parseDouble(y)*10);
dataset.addSeries(series);
dataset.addSeries(series1);
window.repaint();
}
catch(Exception e) {}
}
scanner.close();
}
该图必须是动态的并且具有30秒的跨度.0-30秒必须从30-60秒重新开始,因为传感器读取了必须更改的数据。例如,如果传感器在65秒内正在读取数据,则该图形必须仅具有60-90秒之间的读数。