1

I'm trying to get a Plotly.js plot to display in a Webview in Android.

I have the following Java code (where I'm guessing the problem is):

public String htmlToLoad;

htmlToLoad = ret_data.return_series;//some object I'm getting from server
htmlToLoad = htmlToLoad.replace("\n","");
htmlToLoad = htmlToLoad.replace("\\","");
//myGraphReturn.loadData(htmlToLoad,"text/html",null);//tried but did not work either
myGraphReturn.loadDataWithBaseURL(null,htmlToLoad,"text/html",null,null);

The htmlToLoad variable has final value:

<head>  <script src='https://cdn.plot.ly/plotly-latest.min.js'></script></head><body>    <div id='myDiv'></div>  <script>    var spreads = {      x: ['2017-11-21 12:47:47', '2017-11-21 12:59:28', '2017-12-06 20:10:51'],      y: [5.985, 5.955, 5.895],      mode: 'lines+markers',      name: 'Spread'    };    var data = [spreads];    Plotly.newPlot('myDiv', data);  </script></body>

It's being generated on a server and passed as a string through Firebase. Android isn't throwing any errors, it just isn't displaying anything. Putting this HTML into an online viewer correctly displays the graph.

I'm guessing I have something wrong with my loadData parameters but I can't figure it out.

Antoine Zambelli
  • 724
  • 7
  • 19

0 Answers0