Calculate percentages

Hi,
I'm trying to add percentage fields in PivotClient using entity framework, but I'm getting false values.

 public JsonResult GetData()

        {

            var result = db.OrderData.Select(d => new

            {

               Red = d.RedPieces,

               Ggreen = d.GreenPieces,

               Blue = d.BluePieces,

               Yellow = d.YellowPieces,

               Total = d.TotalPieces,

               percentRed = (d.RedPiecesd.TotalPieces) *100,

               percentGgreen  = (d.GreenPieces d.TotalPieces) *100,

               percentBlue  = (d.BluePiecesd.TotalPieces) *100,

               percentYellow  = (d.YellowPiecesd.TotalPieces) *100,

            }).Where(c => c.Total != 0);

            return new JsonNetResult() { Data = result };

        }

Regards,
Anis

14 Replies

MM Manikandan Murugesan Syncfusion Team January 30, 2018 11:45 AM UTC

Hi Anis, 
 
We are unable to reproduce the reported problem at our end. So, we have prepared a sample as per your requirement, which is available in the below link.  
Note: If you want to set “Percentage” format means, you can set by using the property Format. Please refer below code snippet. 
@(Html.EJ().Pivot().PivotClient("PivotClient1") 
        .DataSource(dataSource => dataSource 
        .Rows(rows => { rows.FieldName("Id").FieldCaption("Id").Add(); }) 
        .Columns(columns => { columns.FieldName("Customer").FieldCaption("Customer").Add(); }) 
                        .Values(values => { values.FieldName("Percent").FieldCaption("Percent").Format("percentage").Add(); })) 
        .Title("Generate Report Finissage").ClientSideEvents(oEve => 
        { 
            oEve.RenderSuccess("setChartProperties") 
  .Load("onLoad") 
  .BeforeExport("Export") 
  .SaveReport("reportSettings") 
  .LoadReport("reportSettings") 
  .FetchReport("reportSettings"); 
        }).IsResponsive(true)) 
 
In the sample, we have added percentage fields in PivotClient using entity framework and its work fine at our end. Please refer the below code snippet and screenshot. 
Code Snippet: 
        [HttpPost] 
        public JsonResult GetData() 
        { 
             
            var data = db.Order.Select(o => new 
            { 
                Id = o.Id, 
                Customer = o.Customer, 
                DateExport = o.DateExport, 
                Qty = o.Qty, 
                Percent = (o.Qty/o.Id) * 100 
            }); 
 
             return Json(data, JsonRequestBehavior.AllowGet); 
        } 
 
Screenshot: 
 
 
If still the problem exists, kindly send your sample that replicating the problem (or) reproduce the problem in the provided sample and revert us. This would be a very helpful for us to investigate the reported problem at our end and provide the solution at earliest. 
 

Thanks, 
Manikandan. 



AN Anis January 30, 2018 03:11 PM UTC

Hi,
Sorry, it's my mistake to not explain the problem properly.
I want to get percentage values regardless of the changes I make in the PivotClient (add fields to the row or column).
Example (please see the screenshot):
C_3 =165 ; C_2 = 182
Total = 2549
percent (-3) = 165 *100 / 2549 = 6.47%
percent (-2) = 182 *100 / 2549 = 7.14%
but in PivotClient I get 3,000.00% and 1,600.00%

Help me please.
Regards,
Anis
 

Attachment: PivotClientPercent_d8e8bae7.rar


MM Manikandan Murugesan Syncfusion Team January 31, 2018 01:08 PM UTC

Hi Anis, 

Sorry. Still, we can’t able to reproduce the reported problem at our end. So, kindly check the below possibilities in your side. 
  • Check the JSON data side in AJAX success method which returns actual result (or) not (which is returned from server). Please refer below screenshot.
Screenshot: 
 
  • There is no need to multiply your values with 100 in GetData() method, while using percentage format. Because, we are multiplying values with 100 in source level, while applying percentage format. Please refer below screenshot.
Screenshot: 
 
 
If still the problem exists, we kindly request you to send your sample replicating the problem (or) reproduce the problem in the sample attached in our previous update. This would be helpful for us to investigate the problem at our end and provide you the solution at the earliest. 

Thanks, 
Manikandan. 



AN Anis January 31, 2018 03:59 PM UTC

Hi,
You find a sample here.
I already add the line and values I need, but I get false percent values, and when I add other fields, I always have false values.
There is another problem in this example, when I try to drag and drop other fields to the line, the browser displays an error message.

Regards,
Anis


RG Ramesh Govindaraj Syncfusion Team February 1, 2018 12:23 PM UTC

Hi Anis, 

Thank you for your sample. 

Please find our below response. 

S.No 
Query 
Response 
 
1. 
 

I already add the line and values I need, but I get false percent values, and when I add other fields, I always have false values. 


We have checked your sample where the JSON data in AJAX success having 0 value for percentage fields. So, PivotClient plots only 0 value for those fields. Please find the below screen-shot for your reference. 

 

 


So, kindly revisit the calculations of percentage fields in server side and pass the data source with correct values to PivotClient control.  

 
2. 
 

There is another problem in this example, when I try to drag and drop other fields to the line, the browser displays an error message. 


We are unable to reproduce any error message on drag and drop operation. Please find the below video for your reference. 


So, kindly provide us the exact replication steps to reproduce the issue with screen-shot/video if possible. Also kindly try different browsers as well and let us know on the same.  



Thanks and Regards, 
Ramesh G 



AN Anis February 1, 2018 03:01 PM UTC

Hi,
Please find the videos below with both errors: Expandable error and percentage error.

Regards,
Anis 


Attachment: PivotClientError_3ce63e4c.rar


MM Manikandan Murugesan Syncfusion Team February 2, 2018 06:10 PM UTC

Hi Anis, 

Please find the response below. 
S.No 
Query 
Comments 
1. 
Expandable error 
We can able to reproduce the issue and we are analyzing the reported problem at our end. We will update the further details about the issue by Monday. 
2. 
Percentage error 
As, we already mentioned, we plot the values which return from controller (server side) only. So, kindly check this at your end in AJAX success method. And, we suspect that you are using integer datatype for values in database. If you divide two integer values the value should be in integer without fraction values. So, kindly try to use float or double datatype in database and controller to get accurate percentage values. 


Thanks, 
Manikandan. 



MM Manikandan Murugesan Syncfusion Team February 5, 2018 12:46 PM UTC

Hi Anis, 
 
We confirmed that “Browser crashed while drag and drop node in PivotClient” is an issue and logged a defect report. The fix for the issue will be available in our Essential Studio 2018 Volume 1 Service Pack 1 release which is estimated to be rolled out in the mid of March 2018. 

Please let us know if any concerns. 

Thanks, 
Manikandan. 



AN Anis February 10, 2018 09:32 AM UTC

Hi,
You seem not understand my problem in percentage calculation. I correct the sample that you find here with videos explaining my problem, the problem is that the PivotClient calculates the sum of the percent values of different data lines, the percentage of a single data row is correct, but in grouping in the PivotClient it makes the sum.
What I want is to calculate the percentage by dividing the variable value by the total value after grouping data in PivotClient.
please watch the video to better understand.

Regards,
Anis


MM Manikandan Murugesan Syncfusion Team February 12, 2018 12:20 PM UTC

Hi Anis, 
 
Currently, we don’t have direct support for percentage calculations based on total value. But, you can achieve this using Calculated Field option at sample level. Please refer below code snippet and screenshot. 
Code Snippet: [cshtml] 
                @(Html.EJ().Pivot().PivotClient("PivotClient1") 
         .DataSource(dataSource => dataSource 
        .Rows(rows => { rows.FieldName("Customer").FieldCaption("Customer").Add(); }) 
 
                        .Values(values => 
                        { 
                            values.FieldName("Red").FieldCaption("Red").Add(); 
                            values.FieldName("Green").FieldCaption("Green").Add(); 
                            values.FieldName("Blue").FieldCaption("Blue").Add(); 
                            values.FieldName("Yellow").FieldCaption("Yellow").Add(); 
                            values.FieldName("Total").FieldCaption("Total").Add(); 
                            values.FieldName("percentRed").FieldCaption("percentRed").Format("percentage").IsCalculatedField(true).Formula("Red/Total").Add(); 
                            values.FieldName("percentGreen").FieldCaption("percentGreen").Format("percentage").IsCalculatedField(true).Formula("Green/Total").Add(); 
                            values.FieldName("percentBlue").FieldCaption("percentBlue").Format("percentage").IsCalculatedField(true).Formula("Blue/Total").Add(); 
                            values.FieldName("percentYellow").FieldCaption("percentYellow").Format("percentage").IsCalculatedField(true).Formula("Yellow/Total").Add(); 
                             
                        })).DisplaySettings(ds=>ds.DefaultView(PivotClientDefaultView.Chart)) 
        .Title("Controle Mesure cm").ClientSideEvents(oEve => 
        { 
            oEve.RenderSuccess("setChartProperties") 
  .Load("onLoad") 
  .BeforeExport("Export") 
  .SaveReport("reportSettings") 
  .LoadReport("reportSettings") 
  .FetchReport("reportSettings"); 
        }).IsResponsive(true).EnableAdvancedFilter(true)) 
 
Screenshot: 
 
 
Meanwhile, we have modified your sample as per your requirement. Please find the sample in below link. 
 
http://www.syncfusion.com/downloads/support/directtrac/135661/ze/SyncfusionMvcPivotClient-1244102139 
 
Please let us know if you have any queries. 
 
Thanks,  Manikandan. 


AN Anis February 15, 2018 06:50 AM UTC

Hi,
Thank you, it is helpful. I hope you add percentage support in PivotClient, and I'm waiting for the fix of the browser crash problem.

Regards,
Anis 


MM Manikandan Murugesan Syncfusion Team February 15, 2018 12:25 PM UTC

Hi Anis, 

Thanks for the reply. 

As we already mentioned that the fix for the issue will be available at 2018 Essential Studio Volume 1 Service Pack 1 release which is estimated to available at mid of March 2018. Until then, please comment the below mentioned line in setChartProperties function in the sample to resolve the issue. 

function setChartProperties(args) { 
                                        this._pivotChart.model.load = "loadTheme"; 
                                        if (args._successAction == undefined || args._successAction == "Filter") { 
                                            this._pivotChart.model.legend.rowCount = 2; 
                                            this._pivotChart.model.primaryXAxis = { title: { text: "Client" }, labelRotation: 270 }; 
                                            //this._pivotChart.model.primaryYAxis = { title: { text: "Defauts" } }; 
                                        } 
} 
 
Please let us know if you have any concerns. 

Thanks, 
Manikandan. 



SA Scintilla Arul Jothi Raj Syncfusion Team March 29, 2018 12:52 PM UTC

Hi Anis, 
The issue - “Browser crashed while drag and drop node in PivotClient could not be included in our Volume 1, SP1, 2018 Service Pack release due to code complexity. But we will definitely include this in our Volume 1, SP2, 2018 Service Pack release which is estimated to be rolled out by the end of April, 2018. 
Sorry for the inconvenience caused. 
Regards, 
Scintilla A. 



SA Scintilla Arul Jothi Raj Syncfusion Team April 25, 2018 04:38 PM UTC

Hi Anis, 
We are glad to announce that our Essential Studio Volume 1, SP 2 2018 (v16.1.0.37) is rolled out and is available for download under the following link. 
https://www.syncfusion.com/forums/137209/essential-studio-2018-volume-1-service-pack-release-v16-1-0-37-available-for-download             
The fix for the issue “Browser crashed while drag and drop node in PivotClient is included in this version. We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance. 
Regards, 
Scintilla A 


Loader.
Up arrow icon