Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Pass JSON string directly to Plotly

I’m trying to specify both the data and layout of my plot with JSON. Is this possible?

From googling, I found an example with Plotly.d3.json, which almost does what I want, but it downloads the JSON from a URL – I can’t seem to pass a JSON string directly. I couldn’t find any documentation on it though.

Something like:

var myJson = '{"data":[{"y":[1,2,3]}],"layout":{"title":"my graph"}}';
var figure = JSON.parse(myJson);

Plotly.newPlot('graph-div', figure.data, figure.layout);

should do the trick.

1 Like