Pizza chart is not being "sliced" using Sfchart

Asked

Viewed 89 times

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
}

Turns out, when mounting the graph the profit slice does not appear, as screenshot below.

inserir a descrição da imagem aqui

Use that website to do. I tried to do as an example from Syncfusion.

  • but it only has a past value, so it represents 100% of the whole.. if you have a 100% parameter or if you have 2 or more references, maybe it splits the pizza, it is not?

  • tries something like { "Brand name": 100030087, "Total sale": 1094, "Total profit": 273.71 }, { "Brand name": 100030087, "Total sale": 700, "Total profit": 230.71 }

  • if your idea is to display full sale and profit slice, try to launch as 2 launches, where one’s valuation is the real value of the sale and the other is profit, probably work

  • So I passed two values Xbindingpath = "Totalvenda", Ybindingpath = "Totallucro". 1094 represents the total sale and 273,71 represents the share of the profit, in a simple arithmetic: Total -(Qtde*cost) this is the rule passed by the client, who gives this value, a percentage of 25% approximately.

  • It seems he only considers the first value, because if I reverse it, he’ll get 100% of the profit.

  • @Michelsimões, the idea is to show a chart by sale. I have a grid with multiple sales, the customer chooses and views on Chart. Putting two sales wouldn’t be the case. I just don’t understand why he doesn’t consider the second value.

  • So my guess is correct about you want to display total sale and profit, it will compare entries of an array, what Voce really needs is to have the different values in different keys, ai yes it will sew each entry as an informational data to mount Chart.

  • @Michelsimões, so I won’t be able to put together a chart with just one sale. I don’t understand what you’re saying. For sale, I have only Total and Profit.

  • A graph must have at least 2 values, if it is not 100% like yours. If yours is at 100% it is assumed that it only takes 1 value. My suggestion was just to treat this delivery of the service, instead of picking 1 matrix, with 3 fields, turn it into 2 matrices, each of them can contain only 1 value. ex: { "Total": 1094 }, ' "Total": 273.71 } . in this way he will understand that Voce has 2 comparative values, launched the proportion in the pizza.

  • @Michelsimões, now it’s clearer. I will load everything in an array, where I have, two fields, {Totalvenda: 1094}, {Totallucro: 273,31}, I think this is it or not?

  • you need to compare the same values, to be able to set them in your code to compare. but that’s right. vc will set your key here: 'Xbindingpath' so the values should come from the same key passed in this. ex: Xbindingpath: "value" and then your array sera {value: "900"}, {value:"100"}. this will probably give a ratio of 10 and 90%

  • the other value that Voce passed Ybindingpath I believe is for when to use inline graphics, or 2D

  • So, you’re confused about this. Look, what my client wants is a sales chart, okay? Show the sale and the profit, until then ok. Now, if I put two sales to compare, is that I’m not understanding your logic, I’m sorry. Why would have to carry two sales?

  • In the Chart documentation, it says that for Chart type Pie two values should be passed as I put it. Here is the documentation: https://help.syncfusion.com/xamarin/sfchart/charttypes#pie-Chart

  • old, you will not carry two sales, Oce will carry 1 sale with the sale values and separate profit in two returns. THAT ONLY. is 1 sale with the values compared, but to be compared they must have the same name. does not mean that they are different sales, only different data for comparison. But it’s just an assumption based on everything I’ve done in JS, PHP and JAVA.

  • @Michelsimões, I get it. It’s just that we stay so far inside the "little house" that we don’t see the surroundings of it. I understand.

  • :) boaa!! if it works out a joinha ;)

  • @Michelsimões, your idea was right about two sales. I did a little different from its implementation and is ok now, I will post mine, but if you post something that brings me the solution mark your answer and not mine. Mine’s not for two days.

  • Congratulations, the important thing is to solve! just watch out for the rule of answering your own questions, some mod can punish you... But I won’t post because I don’t know anything about your language.

  • But what’s wrong with answering your own questions?

  • many people did so in the beginning, threw a question and he answered himself to gain reputation. ta in the group rules something like

  • 1

    I thought that whoever answered the question itself, did not earn points and I think it should be so, because I, for example, ask the question, but I do not wait for the answer. I keep running after and when I find before others, I respond. From now on I will reply editing the post. And most of the time, when I find and others answer, I always give the preference to mark the others and not my own.

  • what pride you aspire to!

Show 18 more comments

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;
            }
        }
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.