Xamarin.android的MpAndroidChart
我正在为我的应用程序使用MpAndroidChart。我可以成功创建piechart,但我有一个问题。我想要一个事件侦听器来处理当用户触摸某个piechart项目时单击的项目。我该如何做 我的代码如下 > int[]ydata={5,2,3,1}; 字符串[]扩展数据={“一”、“二”、“三”、“四”}Xamarin.android的MpAndroidChart,xamarin.android,mpandroidchart,Xamarin.android,Mpandroidchart,我正在为我的应用程序使用MpAndroidChart。我可以成功创建piechart,但我有一个问题。我想要一个事件侦听器来处理当用户触摸某个piechart项目时单击的项目。我该如何做 我的代码如下 > int[]ydata={5,2,3,1}; 字符串[]扩展数据={“一”、“二”、“三”、“四”} PieChart-PieChart; 创建时受保护的覆盖无效(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); //
PieChart-PieChart;
创建时受保护的覆盖无效(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
//从“主”布局资源设置视图
SetContentView(Resource.Layout.Main);
pieChart=FindViewById(Resource.Id.chart1);
pieChart.RotationEnabled=true;
pieChart.HoleRadius=0;
pieChart.SetTransparentCircleAlpha(0);
pieChart.SetCenterTextSize(20);
pieChart.SetDrawEntryLabels(真);
pieChart.SetUsePercentValues(假);
AnimateX(1000,Easing.EasingOption.EaseInOutCubic);
pieChart.Description.Text=“测试”;
addDataSet();
pieChart.SetTouchEnabled(真);
}
私有void addDataSet()
{
List yEntry=新列表();
List xEntry=新列表();
for(int i=0;i
您可以使用设置ChartValueSelectedListener
设置ChartValueSelectedListener
例如,在onCreate()中:
听众:
public class MyListener : Java.Lang.Object, IOnChartValueSelectedListenerSupport
{
Context mContext;
public MyListener(Context context) {
this.mContext = context;
}
public void OnNothingSelected()
{
// throw new NotImplementedException();
}
public void OnValueSelected(Entry e, Highlight h)
{
PieEntry pe = (PieEntry)e;
Toast.MakeText(mContext, pe.Label+ " is clicked, value is "+ pe.Value, ToastLength.Short).Show();
}
}
结果是:pieChart.SetOnChartValueSelectedListener(new MyListener(this));
public class MyListener : Java.Lang.Object, IOnChartValueSelectedListenerSupport
{
Context mContext;
public MyListener(Context context) {
this.mContext = context;
}
public void OnNothingSelected()
{
// throw new NotImplementedException();
}
public void OnValueSelected(Entry e, Highlight h)
{
PieEntry pe = (PieEntry)e;
Toast.MakeText(mContext, pe.Label+ " is clicked, value is "+ pe.Value, ToastLength.Short).Show();
}
}