How to add Highcharts on UIWebView in iOS?

前端 未结 3 1416
旧巷少年郎
旧巷少年郎 2021-02-06 14:33

I am totally new to HighCharts and I referred example http://blog.li-labs.com/developing-ios-apps-with-custom-charting/ and tried same, but on iPad simulator I am getting a blan

相关标签:
3条回答
  • 2021-02-06 15:13

    Useful code for calling .html in UIWebView.

    -(void)viewDidLoad
       {
         NSString *pathOfFile = [[NSBundle mainBundle]  pathForResource:@"chart" ofType:@"html"]; 
    
         NSString *htmlText =[NSString stringWithContentsOfFile:pathOfFile encoding:NSUTF8StringEncoding error:nil];
    
         NSURL *baseURL = [NSURL fileURLWithPath:pathOfFile];
    
        [UIWebView loadHTMLString: htmlText baseURL:baseURL];
       }
    
    0 讨论(0)
  • 2021-02-06 15:14

    Steps:-

    1) First just creat one html file and do the needful code or for trial can copy html code from examples that you get from package http://www.highcharts.com/download

    2) Make sure that the scripts in html should have proper .js links for e.g:- <script src="http://code.highcharts.com/highcharts.js"></script>

    or

    if you want to give it locally you can write <script src="highcharts.js"></script> But make sure that the .js files are there in your application folder.

    3) NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"graph" ofType:@"html"];
       NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
       [obj loadHTMLString:htmlString baseURL:nil];  // Webview *obj;
    

    Hope this help you. In my case its working.

    0 讨论(0)
  • 2021-02-06 15:29

    I tried the suggestions in this post and couldn't get the HighChart load.

    The problem ended up being the "loadHTMLString" call. Passing nil for the baseURL was incorrect. Here's what worked for me - I needed to pass the actual baseURL:

    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:url ofType:@"html"];
    NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
    
    NSURL *baseURL = [NSURL fileURLWithPath:htmlFile];
    
    [webView loadHTMLString:htmlString baseURL:baseURL];
    
    0 讨论(0)
提交回复
热议问题