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.RedPieces/ d.TotalPieces) *100,
percentGgreen = (d.GreenPieces / d.TotalPieces) *100,
percentBlue = (d.BluePieces/ d.TotalPieces) *100,
percentYellow = (d.YellowPieces/ d.TotalPieces) *100,
}).Where(c => c.Total != 0);
return new JsonNetResult() { Data = result };
}
|
@(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)) |
|
[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);
} |
|
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.
|
|
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. |
|
@(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)) |
|
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" } };
}
} |