use of org.xclcharts.event.click.ChartArcListener in project XCL-Charts by xcltapestry.
the class ClickChartsActivity method initActivity.
private void initActivity() {
// 完全动态创建,无须XML文件.
FrameLayout content = new FrameLayout(this);
// 缩放控件放置在FrameLayout的上层,用于放大缩小图表
FrameLayout.LayoutParams frameParm = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
frameParm.gravity = Gravity.BOTTOM | Gravity.RIGHT;
// 图表显示范围在占屏幕大小的90%的区域内
DisplayMetrics dm = getResources().getDisplayMetrics();
int scrWidth = (int) (dm.widthPixels * 0.9);
int scrHeight = (int) (dm.heightPixels * 0.9);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(scrWidth, scrHeight);
// 居中显示
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
// 图表view放入布局中,也可直接将图表view放入Activity对应的xml文件中
final RelativeLayout chartLayout = new RelativeLayout(this);
chartLayout.addView(mCharts, layoutParams);
// 增加控件
((ViewGroup) content).addView(chartLayout);
setContentView(content);
mCharts.setOnPlotClickListener(new ChartArcListener() {
// 可改成pointF,positionRecord,既当前点击点及位置记录
@Override
public void onClick(PointF point, ArcPosition positionRecord) {
if (null == positionRecord)
return;
/**
* 附注,如果数据源是从Activity传给view的,
* 则可在此通过 positionRecord.getDataID() 得到对应的id来取相关信息。
* 同理,其它图形也可依此形式来做,
* 如onClick的参数ArcPosition依图形类别,
* 可替换对应的PointPosition或BarPosition类
*/
Toast.makeText(ClickChartsActivity.this, "[此处为Activity返回的信息] ID:" + positionRecord.getDataID(), Toast.LENGTH_SHORT).show();
}
});
}
Aggregations