我让Java程序使用JFreechart将数据显示为图表,并且当我按图表时,我将Marker与chartMouseClicked一起使用来获取点的任何数据。
现在,我需要通过按键盘上的箭头在图表上移动标记。
这是我的代码,可从图表中获取任何点数据
public void chartMouseClicked(ChartMouseEvent arg0) {
/*for (int m = 0; m < charts.size(); m++) {
System.out.println("charts is "+charts.get(m).title);
}*/
int mouseX = arg0.getTrigger().getX();
int mouseY = arg0.getTrigger().getY();
ChartPanel cp = (ChartPanel) mainPnl.getComponentAt(mouseX, mouseY).getComponentAt(mouseX, mouseY);
//ChartPanel cp = (ChartPanel) arg0.getChart();
String chartName = arg0.getChart().getTitle().getText();
//System.out.println("chrts name "+chartName);
Point2D p = cp.translateScreenToJava2D(new Point(mouseX, mouseY));
plot = (XYPlot) arg0.getChart().getPlot();
//System.out.println("plot = "+plot.getDomainCrosshairValue() + " "+ plot.getRangeCrosshairValue());
ChartRenderingInfo info = cp.getChartRenderingInfo();
Rectangle2D dataArea = info.getPlotInfo().getDataArea();
TimeSeriesCollection tsc = (TimeSeriesCollection) plot.getDataset();
ValueAxis domainAxis = plot.getDomainAxis();
RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
value = tsc.getSeries(0).getDataItem(Math.abs(tsc.getSeries(0).getIndex(rtp))).getValue().doubleValue();
请通过按键盘上的任意键来编写示例代码,说明如何在图表上移动标记。