0

Hi I want to use google graph to plot graph in android webview. I am calling a web service to get the data. I just need to pass those data to javascript to plot the graph. Here is the data that using by google graph api.

 var data = google.visualization.arrayToDataTable([
          ['Frequency', 'HVAC', 'Lighting', 'Overall', 'Cost'],
          ['00:00',100,200,0,80],
          ['00:00',0,0,522,50],
          ['1:00',125,78,0,115],
          ['1:00',0,0,153,125],
          ['2:00',100,90,0,100],
          ['2:00',0,0,119,120]
        ]);

and graph options like

var options = {
          title : 'Monthly Coffee Production by Country',
          vAxis: {title: "Cups"},
          hAxis: {title: "Month"},
          seriesType: "bars",
          isStacked: true,
          series: {3: {type: "line"}}

        };

I think this is a javascript array. I need to pass the data to javascript. Can I pass this kind of array from an android context to javascript?

1 Answer 1

1

You can only pass strings via webview.loadUrl("javascript:myfunction(arg1, ..)") to the webview, but the string can also contain JSON data. Inside the javascript function i.e. myfunction you call JSON.parse(arg1) to convert the string back to a javascript object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.