我浏览了很多很多 stackoverflow 示例,我需要一个更简单的示例。我只想将我的假 mockjax 数组数据连接到我的图表以及当我深入到列时。
任何人都可以解释一个简单明了的方法吗?我是highcharts的新手。
http://jsfiddle.net/cgelinas78/CPZtw/8/
$.getScript("https://raw.github.com/appendto/jquery-mockjax/master/jquery.mockjax.js", function(){
$.mockjax({
url: '/restful/fortune',
responseText: {
status: 'success',
data: [20,50,45]
}
});
$.getJSON('/restful/fortune', function(data) {
$.each(data.data, function(i, value){
var arr = JSON.parse([value])
//alert(arr);
var colors = Highcharts.getOptions().colors,
categories = ['Jan-Mar', 'Apr-May', 'June-Aug', 'Sept-Oct', 'Nov-Dec'],
ddcategories = ['invoice1', 'invoice2', 'invoice3','invoice4', 'invoice5', 'invoice6','invoice7'],
name = 'Browser brands',
data = [{
y: arr,
color: colors[0],
drilldown: {
name: 'MSIE versions',
categories: ddcategories,
data: [value],
color: colors[0]
}
}, {
y: value,
color: colors[1],
drilldown: {
name: 'Firefox versions',
categories: ddcategories,
data: [0.20, 0.83, 1.58, 13.12, 5.43],
color: colors[1]
}
}, {
y: 11.94,
color: colors[2],
drilldown: {
name: 'Chrome versions',
categories: ddcategories,
data: [0.12, 0.19, 0.12, 0.36, 0.32, 9.91, 0.50, 0.22],
color: colors[2]
}
}, {
y: 7.15,
color: colors[3],
drilldown: {
name: 'Safari versions',
categories: ddcategories,
data: [4.55, 1.42, 0.23, 0.21, 0.20, 0.19, 0.14],
color: colors[3]
}
}, {
y: 2.14,
color: colors[4],
drilldown: {
name: 'Opera versions',
categories: ddcategories,
data: [ 0.12, 0.37, 1.65],
color: colors[4]
}
}];
function setChart(name, categories, data, color) {
chart.xAxis[0].setCategories(categories, false);
chart.series[0].remove(false);
chart.addSeries({
name: name,
data: data,
color: color || 'white'
}, false);
chart.redraw();
}
var chart = $('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Browser market share, April, 2011'
},
subtitle: {
text: 'Click the columns to view versions. Click again to view brands.'
},
xAxis: {
categories: categories
},
yAxis: {
title: {
text: 'Total expenses'},
labels: {
formatter: function() {
return '$' + this.value;
}
}
},
plotOptions: {
column: {
cursor: 'pointer',
point: {
events: {
click: function() {
var drilldown = this.drilldown;
if (drilldown) { // drill down
setChart(drilldown.name, drilldown.categories, drilldown.data, drilldown.color);
} else { // restore
setChart(name, categories, data);
}
}
}
},
dataLabels: {
enabled: true,
color: colors[0],
style: {
fontWeight: 'bold'
},
formatter: function() {
return '$' + this.y;
}
}
}
},
tooltip: {
formatter: function() {
var point = this.point,
s = this.x +':<b>'+ '$' + this.y +' USD</b><br/>';
if (point.drilldown) {
s += 'Click to view '+ point.category +' versions';
} else {
s += 'Click to return to browser brands';
}
return s;
}
},
series: [{
name: name,
data: data,
color: 'white'
}],
exporting: {
enabled: false
}
})
.highcharts(); // return chart
});
});
});