How to plot graph using rest-service which contain different format of JSON?

I am very new to PLOTLY!
I am trying to do like: “Make a chart in javascript with a JSon file” and “Load data from external rest service

Whether it is necessarily to have json format like:
{“data”:[
{“x”:[ “giraffes”, “orangutans”, “monkeys” ],
“y”:[ 20, 14, 23]},
{“x”:[ “giraffes”, “orangutans”,“monkeys” ],
“y”:[ 12, 18, 29 ]}
]}
this?
AND
I am using some rest service and trying to fetch data and plot chart; but, I have JSON format like:
{
“msg”: “I have 100 data’s”,
“data”: [
{
“name1”:“value1”,
“x-axis”:“some date”,
“id”:“12345”,
“y-axis”:“some value like 7.8/5.9 etc”
},
{
“name2”:“value2”,
“x-axis”:“some date”,
“id”:“67890”,
“y-axis”:“some value like 7.8/5.9 etc”
},
…etc
]
}

If it is possible to plot graph using my sample json then please some one help me to write the code!

Thank you in advance!

Short answer: no.

plotly.js expect data coordinates to be input in x, y arrays like:

var x = ['some data', 'some other date', /* ... */ ];
var y = [2, 9.0, /* ... */ ];

So you’ll need to convert your data objects to the above form before calling Plotly.plot.

1 Like