gpt4 book ai didi

android - A图表引擎 : how recognise touch in line chart?

转载 作者:行者123 更新时间:2023-11-29 00:17:37 27 4
gpt4 key购买 nike

在我的 android 应用程序中,我正在尝试使用 AChartEngine 向折线图添加触摸。我使用了这个简单的例子:

我在图表中添加了一个点击监听器

this.graphView = ChartFactory.getLineChartView(this, this.graphDataset,
this.graphRenderer);
....

this.graphView.setOnClickListener(buttonClickListenerGraph);

在 buttonClickListenerGraph 方法中我这样做:

SeriesSelection seriesSelection = this.graphView.getCurrentSeriesAndPoint();
if (seriesSelection == null) {
Toast.makeText(this, "No chart element", Toast.LENGTH_SHORT).show();
} else {
// display information of the clicked point
Toast.makeText(
this,
"Chart element in series index " + seriesSelection.getSeriesIndex()
+ " data point index " + seriesSelection.getPointIndex() + " was clicked"
+ " closest point value X=" + seriesSelection.getXValue() + ", Y="
+ seriesSelection.getValue(), Toast.LENGTH_SHORT).show();
}

我还启用了点击

this.graphRenderer.setClickEnabled(true);

其中 graphRenderer 是 XYMultipleSeriesRenderer。

但这总是在触摸时返回“无图表元素”toast。为什么它不识别系列和线条?有人可以帮忙吗?

最佳答案

您可以控制可点击点的“可选缓冲区”,即以点击点为中心的正方形的一半边。 AChartEngine 将搜索整个方形区域以找到可点击点的候选点并返回最近的点。

mRenderer.setSelectableBuffer(circleRadiusInPixels);

关于android - A图表引擎 : how recognise touch in line chart?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25521488/

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