我对 HighCharts 完全陌生,我参考了示例http://blog.li-labs.com/developing-ios-apps-with-custom-charting/ 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 中处理代码和数据的简单视图。
从您喜欢的图表站点下载 Javascript 报告包。就我而言:http://www.highcharts.com/download http://www.highcharts.com/download
将文件添加或导入到 XCode 资源中。 (我建议创建一个名为 JS 的组)。
当向 XCode 添加资源时,它通常会被标记为需要编译。确保文件未列为
正在“编译”。最简单的方法是将文件从
目标 -> 你的项目名称 -> 将源代码编译到目标 -> 你的
项目名称 -> 复制捆绑资源。
创建一个测试 html 文件,或者直接从 HighChart(或任何其他 javascript 图表库)示例文件夹中导入一个文件。就我而言
将其命名为 hcpie.html
确保标签中的任何文件引用不会递归或移动到任何文件夹中(即使它们位于项目中的一个文件夹中)。
例如
RIGHT =
WRONG =
- 在 Interface Designer 中创建一个 UIWebView 并将其链接到您的视图(在我的例子中,我将其命名为 Chart1)。例如
@interface FirstViewController : UIViewController { IBOutlet UIWebView
*图表1; }
@end
-
加载时只需引用 HTML 示例文件即可。
NSString *pathOfFile = [[NSBundle mainBundle] pathForResource:@”hcpie”
ofType:@”html”]; NSString *htmlText = [NSString
stringWithContentsOfFile:pathOfFile 编码:NSUTF8StringEncoding
错误:无];
NSURL *baseURL = [NSURL fileURLWithPath:pathOfFile];
[chart1 loadHTMLString: htmlText baseURL:baseURL];
[超级viewDidLoad];
}