我完全陌生的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的代码和数据的简单示意图。
从您的preferd图网站下载JavaScript报告包。 在我的情况: http://www.highcharts.com/download
添加或文件导入XCode的资源。 (我建议创建一个名为JS组)。
当添加一个资源的Xcode它通常会被标记为需要进行编译。 确保文件不被列为被“编译”。 最简单的方法就是简单地从目标拖动文件 - >项目名称 - >编译的源代码到目标 - >您的项目名称 - >复制包资源。
创建一个测试HTML文件或简单地导入一个从HighChart(或任何其他JavaScript库图)示例文件夹中。 在我来说,我将其命名为hcpie.html
确保代码的所有文件引用不递归或移动到任意文件夹中(即使是在一个项目中的)。 例如
RIGHT =
WRONG =
- 创建界面设计师中一个UIWebView并将其链接到您的视图(在我的情况下,我把它命名为chart1)。 例如
@interface FirstViewController:的UIViewController {IBOutlet中的UIWebView * chart1; } }
@结束
只需加载时引用的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中];
}