Black Lives Matter. Please consider donating to Black Girls Code today.

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:
{“x”:[ “giraffes”, “orangutans”, “monkeys” ],
“y”:[ 20, 14, 23]},
{“x”:[ “giraffes”, “orangutans”,“monkeys” ],
“y”:[ 12, 18, 29 ]}
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”: [
“x-axis”:“some date”,
“y-axis”:“some value like 7.8/5.9 etc”
“x-axis”:“some date”,
“y-axis”:“some value like 7.8/5.9 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