-
-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to save the JSON object #35
Comments
Hi. It looks like you can do what you want. I'm not quite sure what exactly you wanted to extract, but here is an example of what you can do. I first create a plot object julia> using PlotlyJS
julia> using JSON
julia> t = scatter(;y=randn(10))
scatter with field y
julia> p = plot(t); I'm not 100% sure what you wanted from the json. First, I get the entire corresponding json which describes both data and layout. I also show you can get each of them separately. julia> println(json(p.plot))
{"data":[{"type":"scatter","y":[-0.36056101860419904,0.010378695002435814,0.6862578856068621,1.1708753904672111,0.02193530205277864,-1.9889936066496465,0.5101794208421222,-1.6809582341634173,0.13301085439172255,1.6620886473634708]}],"layout":{"margin":{"r":50,"l":50,"b":50,"t":60}}}
julia> println(json(p.plot.data))
[{"type":"scatter","y":[-0.36056101860419904,0.010378695002435814,0.6862578856068621,1.1708753904672111,0.02193530205277864,-1.9889936066496465,0.5101794208421222,-1.6809582341634173,0.13301085439172255,1.6620886473634708]}]
julia> println(json(p.plot.layout))
{"margin":{"r":50,"l":50,"b":50,"t":60}} Additionally, if you wanted to just get the HTML on its own (without having to pass it anywhere) then you could get the html by using julia> println(PlotlyJS.html_body(p.plot))
<div id="b0e29592-832f-41a5-9421-804cc36044d2" class="plotly-graph-div"></div>
<script>
window.PLOTLYENV=window.PLOTLYENV || {};
window.PLOTLYENV.BASE_URL="https://plot.ly";
Plotly.newPlot('b0e29592-832f-41a5-9421-804cc36044d2', [{"type":"scatter","y":[-0.36056101860419904,0.010378695002435814,0.6862578856068621,1.1708753904672111,0.02193530205277864,-1.9889936066496465,0.5101794208421222,-1.6809582341634173,0.13301085439172255,1.6620886473634708]}], {"margin":{"r":50,"l":50,"b":50,"t":60}}, {showLink: false});
</script> Kind of a lot to read. Does that help? |
Thanks @cc7768 ! This was really useful :) |
Quick note: you can also do And you can do |
Hi! I want to export/save the JSON plot data, in order to load it in a HTML and modify it using JS to interact with the plot in different ways. Is it possible to do that? Thanks!
The text was updated successfully, but these errors were encountered: