如何在iOS中添加Highcharts上的UIWebView?(How to add Highcha

2019-09-01 17:18发布

我完全陌生的HighCharts和我提到例如http://blog.li-labs.com/developing-ios-apps-with-custom-charting/并试图相同,但在iPad模拟器我得到一个空白屏幕。

我刚才提到的堆栈溢出的问题,但它仍然是行不通的。 谁能告诉我要去哪里错了。

编辑:代码在我的HTML文件:

 <!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Highcharts Example</title>

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <script type="text/javascript">
$(function () {

        // Radialize the colors
        Highcharts.getOptions().colors = Highcharts.map(Highcharts.getOptions().colors, function(color) {
            return {
                radialGradient: { cx: 0.5, cy: 0.3, r: 0.7 },
                stops: [
                    [0, color],
                    [1, Highcharts.Color(color).brighten(-0.3).get('rgb')] // darken
                ]
            };
        });

        // Build the chart
        $('#container').highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            },
            title: {
                text: 'Browser market shares at a specific website, 2010'
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage}%</b>',
                percentageDecimals: 1
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        color: '#000000',
                        connectorColor: '#000000',
                        formatter: function() {
                            return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
                        }
                    }
                }
            },
            series: [{
                type: 'pie',
                name: 'Browser share',
                data: [
                    ['Firefox',   45.0],
                    ['IE',       26.8],
                    {
                        name: 'Chrome',
                        y: 12.8,
                        sliced: true,
                        selected: true
                    },
                    ['Safari',    8.5],
                    ['Opera',     6.2],
                    ['Others',   0.7]
                ]
            }]
        });
    });


        </script>
    </head>
    <body>
<!--<script src="../../js/highcharts.js"></script>-->
<!--<script src="../../js/modules/exporting.js"></script>-->

<script type="text/javascript" src="highcharts.js"></script>
<script type="text/javascript" src="exporting.js"></script>

<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
    </body>
</html>

如何添加和使用Xcode中的Javascript库

下面是我如何处理在Xcode的代码和数据的简单示意图。

  1. 从您的preferd图网站下载JavaScript报告包。 在我的情况: http://www.highcharts.com/download

  2. 添加或文件导入XCode的资源。 (我建议创建一个名为JS组)。

  3. 当添加一个资源的Xcode它通常会被标记为需要进行编译。 确保文件不被列为被“编译”。 最简单的方法就是简单地从目标拖动文件 - >项目名称 - >编译的源代码到目标 - >您的项目名称 - >复制包资源。

  4. 创建一个测试HTML文件或简单地导入一个从HighChart(或任何其他JavaScript库图)示例文件夹中。 在我来说,我将其命名为hcpie.html

  5. 确保代码的所有文件引用不递归或移动到任意文件夹中(即使是在一个项目中的)。 例如

RIGHT =

WRONG =

  1. 创建界面设计师中一个UIWebView并将其链接到您的视图(在我的情况下,我把它命名为chart1)。 例如

@interface FirstViewController:的UIViewController {IBOutlet中的UIWebView * chart1; } }

@结束

  1. 只需加载时引用的HTML示例文件。

    • (无效)viewDidLoad中{

的NSString * pathOfFile = [[一个NSBundle mainBundle] pathForResource:@” hcpie” ofType:@” HTML”]; 的NSString *的htmlText = [NSString的stringWithContentsOfFile:pathOfFile编码:NSUTF8StringEncoding误差:无];

NSURL * =基本URL [NSURL fileURLWithPath:pathOfFile];

[chart1 loadHTMLString:的htmlText基本URL:基本URL];

[超级viewDidLoad中];

}

Answer 1:

脚步:-

1)首先创造只是一个HTML文件,并做要紧代码或试用可以从你的包获得的例子将HTML代码复制http://www.highcharts.com/download

2)确保在HTML脚本应该有一个适当的如链接名为.js: - <script src="http://code.highcharts.com/highcharts.js"></script>

要么

如果你想在本地给它,你可以写<script src="highcharts.js"></script>但是,请确保.js文件是否有你的应用程序文件夹。

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;

希望这帮助你。 在我的情况下,它的工作。



Answer 2:

我想建议在这个岗位,并不能得到HighChart负荷。

这个问题最终被“loadHTMLString”电话。 路过的无基本URL是不正确的。 下面是我工作 - 我需要通过实际的基本URL:

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];


Answer 3:

在UIWebView中调用的.html有用的代码。

-(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];
   }


文章来源: How to add Highcharts on UIWebView in iOS?