gpt4 book ai didi

java - 单击 XYPlot 的系列时获取系列标识符

转载 作者:行者123 更新时间:2023-11-30 03:03:57 24 4
gpt4 key购买 nike

我在 XYPlot 上绘制了 4 个系列。我想在点击XYPlot时获取系列ID(参见//int seriesId = ???;)。可能吗?

   _chartPanel.addChartMouseListener(new ChartMouseListener() {
@Override
public void chartMouseClicked(ChartMouseEvent cme)
{
MouseEvent me = cme.getTrigger();
XYPlot plot = (XYPlot) cme.getChart().getPlot();
if (me.getClickCount() == 2)
{
plot.clearAnnotations();
}
else
{
Rectangle2D dataArea = _chartPanel.getScreenDataArea();
plot.clearAnnotations();
ValueAxis xAxis = plot.getDomainAxis();
ValueAxis yAxis = plot.getRangeAxis();
double x = xAxis.java2DToValue(cme.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM);
double y = yAxis.java2DToValue(cme.getTrigger().getY(), dataArea, RectangleEdge.LEFT);
if (!xAxis.getRange().contains(x)) {
x = Double.NaN;

//int seriesId = ???;

DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.CEILING);
XYPointerAnnotation pt = new XYPointerAnnotation("Lat: " + df.format(y) + "\n Lon: " + df.format(x), x, y, 0.2);
pt.setBackgroundPaint(new Color(103,154,236));
// pt.setArrowPaintnew Color(103,154,236)d);
pt.setFont(_font);
pt.setPaint(Color.LIGHT_GRAY);
plot.addAnnotation(pt);
}
}

最佳答案

如图here ,您可以检索ChartEntity来自 ChartMouseEvent。对于 XYItemEntity 类型的 ChartEntity ,您可以通过 getDataset() 获取数据集,并通过 getSeriesIndex() 获取系列索引。

ChartEntity ce = cme.getEntity();
if (ce instanceof XYItemEntity) {
XYItemEntity e = (XYItemEntity) ce;
System.out.println("Dataset: " + e.getDataset());
System.out.println("Series index: " + e.getSeriesIndex());
}

关于java - 单击 XYPlot 的系列时获取系列标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35266855/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com