我从xcode传递了json编码的字符串(例如$ TEXT2由[“chrome”,“15”,“firefox”,“20”])为一个数组(例如arr )在javascript.Now我想要将包含json字符串的数组动态地传递给Highcharts Pie。 HTML代码是将动态json数组传递给Highcharts饼图
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=20, user-scalable=no;" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Pie chart</title>
<!-- 1. Add these JavaScript inclusions in the head of your page -->
<script type="text/javascript" src="jquery-1.6.2.js"></script>
<script type="text/javascript" src="highcharts.js"></script>
<script type="text/javascript" src="jquery.form.js"></script>
<!-- 2. Add the JavaScript to initialize the chart on document ready -->
<script type="text/javascript">
var chart;
var arr = $TEXT2;
$(document).ready(function(){
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Interactive Pie'
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
}
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: []
}]
});
});
</script>
<body>
<br>
<!-- 3. Add the container -->
<div id="container" style="width: 300px; height: 350px; margin: 0 auto"></div>
<!-- 2. Add the JavaScript to initialize the chart on document ready -->
</body>
</html>
我想使用getjson方法,虽然m不知道它的用法。 因为我想通过我的数组即ARR在Highcharts数据[],我是这样做的:
$.getJSON("arr", function(json) {
chart.series = json;
var chart = new Highcharts.Chart(chart);
});
谁能帮我上DIS。 在此先感谢。
我想在JS返回数组转换,我尝试了几种方法,但不能做此格式如。 [['chrome',15],['firefox',20]]这是Highcharts的可接受格式 – rehan
已完成的家伙,非常感谢您的帮助:) – rehan
所以在这一刻,一切运作良好? –