如何从Xamarin形式的MpAndroidChart(UltimateXF)获取单击的项目

时间:2019-04-26 09:16:17

标签: c# charts xamarin.forms

我正在为我的应用程序使用MpAndroidChart(UltimateXF)。我成功创建了饼图,但是当用户触摸饼图项之一时,无法创建事件侦听器来获取单击的项。

这是我的UltimateXF库

https://nuget.org/packages/UltimateXF/

这是我的代码。...

public partial class HomePage : ContentPage
{
    public HomePage ()
    {
        InitializeComponent ();

        var entries = new List<PieEntry>();

        entries.Add(new PieEntry(40, "Life"));
        entries.Add(new PieEntry(60, "General"));

        var dataSet4 = new PieDataSet(entries, "")
        {
            Colors = new List<Color>()
            {
                Color.Accent, Color.Chocolate
            },
            ValueLineColor = Color.Blue,
            SliceSpace = 2f,
            ValueFormatter = new CustomPercentDataSetValueFormatter()
        };
        var data4 = new PieChartData(dataSet4)
        {

        };

        var dataSet5 = new PieDataSet(entries, "")
        {
        };


        pieChart.ChartData = data4;
        pieChart.RotateEnabled = false;

    }
}


public class CustomPercentDataSetValueFormatter : IDataSetValueFormatter
{
    public string GetFormattedValue(float value, int dataSetIndex)
    {
        return value + "%";
    }
}

0 个答案:

没有答案