cancel
Showing results for 
Search instead for 
Did you mean: 

How to create series in a fiori line graph

former_member592880
Participant
0 Kudos

I have to make a vendor comparison line graph. it is supposed to create series based on the vendor number it gets from the OData service. here is what I've been trying (it worked with a static json file but wont work with a odata service)

XML

 <chart:Line id="idVendorCompareGraph" width="100%" height="100%"></chart:Line>

JS

 var that = this;
   var sServiceUrl = "/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV";
   var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true);
   var oVendorCompareGraph = that.getView().byId("idVendorCompareGraph");
   var vendorCompare = "/VendorComparisonSet?$filter=Plant eq '3621' and Material eq '000000000000200000'";
   oModel.setUseBatch(false);
   oModel.read(vendorCompare, {
    success: function(oData, response) {
     if (oData.results !== "undefined" || oData.results !== null) {
      var UsageModel = new sap.ui.model.json.JSONModel({
       "VCdata": oData.results
      });
     }
     var oDim = {
      dimensions: [{
       axis: 1,
       name: "Month",
       value: "{Month}"
      }, {
       axis: 2,
       name: "Vendor",
       value: "{Vendor}"
      }],
      measures: [{
       group: 1,
       name: "NetPrice",
       value: "{NetPrice}"
      }, {
       group: 2,
       name: "Quantity",
       value: "{Quantity}"
      }],
      data: {
       path: "VCdata"
      }
     };
     var oDataset = new sap.viz.core.FlattenedDataset(oDim);
     oDataset.setModel(UsageModel);
     oVendorCompareGraph.setDataset(oDataset);
     alert("success");
    },
    error: function(error) {
     var message = "Error";
     sap.m.MessageBox.show(message, sap.m.MessageBox.Icon.ERROR, "Error");
    }
   });

OData

{
  "d" : {
    "results" : [
{
        "__metadata" : {
          "id" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900147',Material='200000',Plant='')",
          "uri" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900147',Material='200000',Plant='')",
          "type" : "AAG362.MM_PURCHASE_APPROVAL_SRV.VendorComparison"
        },
        "Vendor" : "900147",
        "Material" : "200000",
        "Plant" : "",
        "Month" : "201710",
        "Count" : 1,
        "Quantity" : "0.00",
        "NetPrice" : "115.00",
        "AvgPrice" : "115.00",
        "AvgQty" : "0.00",
        "PlanPrice1" : "0.00",
        "PlanPrice2" : "0.00"
      },
      {
        "__metadata" : {
          "id" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900147',Material='200000',Plant='')",
          "uri" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900147',Material='200000',Plant='')",
          "type" : "AAG362.MM_PURCHASE_APPROVAL_SRV.VendorComparison"
        },
        "Vendor" : "900147",
        "Material" : "200000",
        "Plant" : "",
        "Month" : "201711",
        "Count" : 1,
        "Quantity" : "0.00",
        "NetPrice" : "58.30",
        "AvgPrice" : "58.30",
        "AvgQty" : "0.00",
        "PlanPrice1" : "0.00",
        "PlanPrice2" : "0.00"
      },
      {
        "__metadata" : {
          "id" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900173',Material='200000',Plant='')",
          "uri" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900173',Material='200000',Plant='')",
          "type" : "AAG362.MM_PURCHASE_APPROVAL_SRV.VendorComparison"
        },
        "Vendor" : "900173",
        "Material" : "200000",
        "Plant" : "",
        "Month" : "201710",
        "Count" : 1,
        "Quantity" : "1.00",
        "NetPrice" : "100.00",
        "AvgPrice" : "100.00",
        "AvgQty" : "1.00",
        "PlanPrice1" : "0.00",
        "PlanPrice2" : "0.00"
      },
      {
        "__metadata" : {
          "id" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900177',Material='200000',Plant='')",
          "uri" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900177',Material='200000',Plant='')",
          "type" : "AAG362.MM_PURCHASE_APPROVAL_SRV.VendorComparison"
        },
        "Vendor" : "900177",
        "Material" : "200000",
        "Plant" : "",
        "Month" : "201709",
        "Count" : 1,
        "Quantity" : "100.00",
        "NetPrice" : "0.00",
        "AvgPrice" : "0.00",
        "AvgQty" : "100.00",
        "PlanPrice1" : "0.00",
        "PlanPrice2" : "0.00"
      },
      {
        "__metadata" : {
          "id" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900201',Material='200000',Plant='')",
          "uri" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900201',Material='200000',Plant='')",
          "type" : "AAG362.MM_PURCHASE_APPROVAL_SRV.VendorComparison"
        },
        "Vendor" : "900201",
        "Material" : "200000",
        "Plant" : "",
        "Month" : "201712",
        "Count" : 1,
        "Quantity" : "0.00",
        "NetPrice" : "1000.00",
        "AvgPrice" : "1000.00",
        "AvgQty" : "0.00",
        "PlanPrice1" : "0.00",
        "PlanPrice2" : "0.00"
      },
      {
        "__metadata" : {
          "id" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900201',Material='200000',Plant='')",
          "uri" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900201',Material='200000',Plant='')",
          "type" : "AAG362.MM_PURCHASE_APPROVAL_SRV.VendorComparison"
        },
        "Vendor" : "900201",
        "Material" : "200000",
        "Plant" : "",
        "Month" : "201801",
        "Count" : 1,
        "Quantity" : "0.00",
        "NetPrice" : "5000.00",
        "AvgPrice" : "5000.00",
        "AvgQty" : "0.00",
        "PlanPrice1" : "0.00",
        "PlanPrice2" : "0.00"
      },
      {
        "__metadata" : {
          "id" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900234',Material='200000',Plant='')",
          "uri" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900234',Material='200000',Plant='')",
          "type" : "AAG362.MM_PURCHASE_APPROVAL_SRV.VendorComparison"
        },
        "Vendor" : "900234",
        "Material" : "200000",
        "Plant" : "",
        "Month" : "201711",
        "Count" : 1,
        "Quantity" : "0.00",
        "NetPrice" : "35.00",
        "AvgPrice" : "35.00",
        "AvgQty" : "0.00",
        "PlanPrice1" : "0.00",
        "PlanPrice2" : "0.00"
      },
      {
        "__metadata" : {
          "id" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900235',Material='200000',Plant='')",
          "uri" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900235',Material='200000',Plant='')",
          "type" : "AAG362.MM_PURCHASE_APPROVAL_SRV.VendorComparison"
        },
        "Vendor" : "900235",
        "Material" : "200000",
        "Plant" : "",
        "Month" : "201711",
        "Count" : 1,
        "Quantity" : "0.00",
        "NetPrice" : "36.00",
        "AvgPrice" : "36.00",
        "AvgQty" : "0.00",
        "PlanPrice1" : "0.00",
        "PlanPrice2" : "0.00"
      },
      {
        "__metadata" : {
          "id" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900236',Material='200000',Plant='')",
          "uri" : "http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV/VendorComparisonSet(Vendor='900236',Material='200000',Plant='')",
          "type" : "AAG362.MM_PURCHASE_APPROVAL_SRV.VendorComparison"
        },
        "Vendor" : "900236",
        "Material" : "200000",
        "Plant" : "",
        "Month" : "201711",
        "Count" : 1,
        "Quantity" : "0.00",
        "NetPrice" : "36.00",
        "AvgPrice" : "36.00",
        "AvgQty" : "0.00",
        "PlanPrice1" : "0.00",
        "PlanPrice2" : "0.00"
      }
    ]
  }
}


What am I doing wrong?? please help...

Accepted Solutions (1)

Accepted Solutions (1)

maheshpalavalli
Active Contributor

I think you need to mention '/' in the path:

     
// OLD code
 data: {
       path: "VCdata"
      }

//New Code

      data: {
       path: "/VCdata"
      }

Also for the line char using viz frames, the code is different, I hope there is no problem with xml view.

https://ui5.sap.com/#/sample/sap.viz.sample.Line/code

 <viz:VizFrame id="idVizFrame" uiConfig="{applicationSet:'fiori'}"
                height='100%' width="100%" vizType='line'>

BR,

Mahesh

former_member592880
Participant
0 Kudos

Thank you very much Sir

Answers (0)