Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ashwinr87

macrumors member
Original poster
Mar 9, 2011
81
0
I am trying to implement RGraphs into my iphone application. However, I am unable to get how to include the files and how to run the javascript on my UIWebview so that it would display the graph.

It would be great if someone could help me out.
 

phantax

macrumors member
Feb 2, 2009
72
0
Something like RGraphs is meant for adding graphing elements to a website. I guess technically could include the files in your app bundle and just access the local paths with Safari (if you are allowed to do that), in which case the JavaScript should execute automatically.

This is really not the right tool for the job to generate local graphs, and is kind of a kludge.

Have you looked into any native iOS graphing libraries like CorePlot?
 

ashwinr87

macrumors member
Original poster
Mar 9, 2011
81
0
thanks for the reply.. I did look into Coreplot but it was a bit too complicated for me.. so I was looking into some alternatives..

Something like RGraphs is meant for adding graphing elements to a website. I guess technically could include the files in your app bundle and just access the local paths with Safari (if you are allowed to do that), in which case the JavaScript should execute automatically.

This is really not the right tool for the job to generate local graphs, and is kind of a kludge.

Have you looked into any native iOS graphing libraries like CorePlot?
 

ashwinr87

macrumors member
Original poster
Mar 9, 2011
81
0
Calling Javascript using UIWebView

I am trying to call a javascript in a html page using the function -

Code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:@"BasicGraph.html"];
NSURL *urlStr = [NSURL fileURLWithPath:writablePath];

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *myPathInfo = [[NSBundle mainBundle] pathForResource:@"BasicGraph" ofType:@"html"];
[fileManager copyItemAtPath:myPathInfo toPath:writablePath error:NULL];

[graphView loadRequest:[NSURLRequest requestWithURL:urlStr]];
[graphView stringByEvaluatingJavaScriptFromString:@"methodName()"];

Here is the javascript on the html page -

Code:
<script>
function methodName()
    {
        alert(hi);
    } 
window.onload = function ()
    {
      // Code Omitted
    }
</script>

However, the function methodName() is not getting called but after window.onload = function () everything is working fine..

I am trying to integrate RGraphs into my application and Basic.html is the html page in which the javascripts are written.

It would be great if someone could help me out with this.
 

phantax

macrumors member
Feb 2, 2009
72
0
I think you are just missing a semicolon.

Code:
[graphView stringByEvaluatingJavaScriptFromString:@"methodName()[COLOR="Red"];[/COLOR]"];

Alternatively, can't you just call methodName() in the window.onload? Is there a reason you want to call it natively from the app?

Also, make sure you are calling this in webViewDidFinishLoad so that your JavaScript code is actually available when you are trying to run it.
 

ashwinr87

macrumors member
Original poster
Mar 9, 2011
81
0
Thank you.. I figured out that just before I saw your reply.. and I forgot to set the webview delegate to self.. now it is working..
thanks...

I think you are just missing a semicolon.

Code:
[graphView stringByEvaluatingJavaScriptFromString:@"methodName()[COLOR="Red"];[/COLOR]"];

Alternatively, can't you just call methodName() in the window.onload? Is there a reason you want to call it natively from the app?

Also, make sure you are calling this in webViewDidFinishLoad so that your JavaScript code is actually available when you are trying to run it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.