Chart pizza is not being "sliced" using SfChart

1

I made this chart using Syncfusion Chart,

private async void CriaChart()
{
    SfChart chart = new SfChart();
    DataService dataService = new DataService();

    try
    {
        PieSeries pieSeries = new PieSeries()
        {
            ItemsSource = await dataService.GetDataGrid(IdOrcamento),
            XBindingPath = "TotalVenda",
            YBindingPath = "TotalLucro",
            ExplodeIndex = 1,
            ExplodeRadius = 10
        };

        pieSeries.DataMarker = new ChartDataMarker();
        chart.Legend = new ChartLegend();
        chart.Title.Text = "Gráfico da Venda";
        pieSeries.Label = "TotalLucro";
        pieSeries.DataMarker.LabelContent = LabelContent.Percentage;
        chart.Series.Add(pieSeries);

        this.Content = chart;

    }
    catch(Exception ex)
    {
        string err = ex.Message;
    }
}

My service gives me this:

{
    "IdOrcamento": 100030087,
    "TotalVenda": 1094,
    "TotalLucro": 273.71
}

It turns out that when mounting the graph the profit slice does not appear, as screenshot below.

Iusethis site to do it. I tried to do as the example of Syncfusion.

    
asked by anonymous 20.10.2017 / 19:59

1 answer

1

This is my class

public class DataModelGrid
    {
        DataService dataService = new DataService();
        public List<LiberacaoItensGrid> itensGrid = new List<LiberacaoItensGrid>();
        public List<GeraGrafico> GeraChart { get; set; }
        public double IdOrcamento { get; set; }
        public double TotalVenda { get; set; }
        public double TotalLucro { get; set; }
        public DataModelGrid(double id)
        {
            GetService(id);
            GeraChart = new List<GeraGrafico>();
            GeraChart.Add(new GeraGrafico() { Assunto = "Vendas", Total = TotalVenda });
            GeraChart.Add(new GeraGrafico() { Assunto = "Lucro", Total = TotalLucro });
        }        
        public async void GetService(double id)
        {
            itensGrid = await dataService.GetDataGrid(id);
            foreach (var item in itensGrid)
            {
                this.IdOrcamento = item.IdOrcamento;
                this.TotalVenda = item.TotalVenda;
                this.TotalLucro = item.TotalLucro;
            }
        }
        public class GeraGrafico
        {
            public string Assunto { get; set; }
            public double Total { get; set; }
        }
    }

Here I get my service data:

public async Task<List<LiberacaoItensGrid>> GetDataGrid(double id)
        {
            try
            {
                var client = new HttpClient();
                string url = $"http://www.inetglobal.com.br/autorizador/api/getliberaitens/{id}";
                var response = await client.GetStringAsync(url);
                var itenslib = JsonConvert.DeserializeObject<List<LiberacaoItensGrid>>(response);

                return itenslib.ToList();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

And the creation of the Chart

[XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class Grafico : ContentPage
    {
        SfChart chart = new SfChart();
        DataModelGrid dataModelGrid;
        public double IdOrcamento { get; set; }

        public Grafico(double _idorcamento)
        {
            InitializeComponent();
            CriaChart(_idorcamento);
        }

        private void CriaChart(double id)
        {
            SfChart chart = new SfChart();
            dataModelGrid = new DataModelGrid(id);

            try
            {
                PieSeries pieSeries = new PieSeries()
                {
                    ItemsSource = dataModelGrid.GeraChart, 
                    XBindingPath = "Assunto",
                    YBindingPath = "Total"
                    //ExplodeIndex = 1,
                    //ExplodeRadius = 10
                };

                pieSeries.DataMarker = new ChartDataMarker();
                chart.Legend = new ChartLegend();
                chart.Title.Text = "Gráfico da Venda";
                pieSeries.Label = "Total";
                pieSeries.DataMarker.LabelContent = LabelContent.Percentage;
                chart.Series.Add(pieSeries);

                this.Content = chart;

            }
            catch(Exception ex)
            {
                string err = ex.Message;
            }
        }
    }
    
24.10.2017 / 15:04