Implementing RGraph in iOS applications

Discussion in 'iOS Programming' started by ashwinr87, Jan 13, 2012.

  1. ashwinr87 macrumors member

    Mar 9, 2011
    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.
  2. phantax macrumors member

    Feb 2, 2009
    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?
  3. ashwinr87 thread starter macrumors member

    Mar 9, 2011
    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..

  4. ashwinr87 thread starter macrumors member

    Mar 9, 2011
    Calling Javascript using UIWebView

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

    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 -

    function methodName()
    window.onload = function ()
          // Code Omitted
    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.
  5. phantax macrumors member

    Feb 2, 2009
    I think you are just missing a semicolon.

    [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.
  6. ashwinr87 thread starter macrumors member

    Mar 9, 2011
    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..


Share This Page