cancel
Showing results for 
Search instead for 
Did you mean: 

Problem getting VIZ Charts to consume my JSON data

jason_latko
Advisor
Advisor
0 Kudos

Experts,

I am working on a very basic viz chart SAPUI5 example.  My preferred JSON that I want to use to populate the chart looks like this:

"data": [

{"object": {

    "ave":".173",

    "name":"Fergie Jenkins",

    "team":"Chicago Cubs",

    "OnBasePercentage":".250"

}}

,

{"object": {

    "ave":".300",

    "name":"Alfonso Soriano",

    "team":"Chicago Cubs",

    "OnBasePercentage":".375"

}}

,

{"object": {

    "ave":".130",

    "name":"Gaylord Perry",

    "team":"San Francisco Giants",

    "OnBasePercentage":".205"

}}

]

The above JSON doesn't work with these dimensions:

    var dataSet = new sap.viz.ui5.data.FlattenedDataset({

        dimensions: [

          { axis: 1, name: 'Player', value: "{name}" },

          { axis: 2, name: 'Team', value: "{team}" }

        ],

        measures: [

          { name: 'Average', value: '{ave}' }

        ],

        data: { path: "/data" }

    });

Is there a way to tell this dimensions construct that I have a parent node in my JSON for each record of "object"?  I tried {object.name}, but that did not work.  Is there a syntax change I can make to reference the field values that would include the "object" reference somehow?

My chart works fine when I use the following JSON without the "object" wrapper, but this is not my preferred format:

"data": [

{

    "AgentryObjectName": "",

    "ave":".173",

    "name":"Fergie Jenkins",

    "team":"Chicago Cubs",

    "OnBasePercentage":".250"

}

,

{

    "AgentryObjectName": "",

    "ave":".300",

    "name":"Alfonso Soriano",

    "team":"Chicago Cubs",

    "OnBasePercentage":".375"

}

,

{

    "AgentryObjectName": "",

    "ave":".130",

    "name":"Gaylord Perry",

    "team":"San Francisco Giants",

    "OnBasePercentage":".205"

}

]

Any help would be greatly appreciated.  Thanks!

Jason Latko - Senior Product Developer at SAP

Accepted Solutions (1)

Accepted Solutions (1)

former_member196805
Contributor
0 Kudos

Have you tried below?

        dimensions: [

          { axis: 1, name: 'Player', value: "{object/name}" },

          { axis: 2, name: 'Team', value: "{object/team}" }

        ],

        measures: [

          { name: 'Average', value: '{object/ave}' }

        ],

jason_latko
Advisor
Advisor
0 Kudos

Wow, that was easy.  As usual it was a 1 character change from "." to "/".  Thanks guys!

Jason Latko - Senior Product developer at SAP

Answers (1)

Answers (1)

Former Member
0 Kudos

Chapman is correct see sample

JS Bin - Collaborative JavaScript Debugging