我正在关注http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/drilldown/async/制作钻取图表的链接.
我无法理解如何设置drilldowns = {}(动态来自ajax调用)和 series = drilldowns[e.point.name];
drilldowns = {
'Animals': {
name: 'Animals',
data: [
['Cows', 2],
['Sheep', 3]
]
},
'Fruits': {
name: 'Fruits',
data: [
['Apples', 5],
['Oranges', 7],
['Bananas', 2]
]
},
'Cars': {
name: 'Cars',
data: [
['Toyota', 1],
['Volkswagen', 2],
['Opel', 5]
]
}
}
Run Code Online (Sandbox Code Playgroud)
我试图搜索.addSeriesAsDrilldown(e.point, series);
请帮助我如何通过$ .ajax调用实现向下钻取.
$(function () {
// Create the chart
$('#container').highcharts({
chart: {
type: 'column',
events: {
drilldown: function (e) {
if (!e.seriesOptions) {
var chart = this,
drilldowns = {
'Animals': {
name: 'Animals',
data: [
['Cows', 2],
['Sheep', 3]
]
},
'Fruits': {
name: 'Fruits',
data: [
['Apples', 5],
['Oranges', 7],
['Bananas', 2]
]
},
'Cars': {
name: 'Cars',
data: [
['Toyota', 1],
['Volkswagen', 2],
['Opel', 5]
]
}
},
series = drilldowns[e.point.name];
// Show the loading label
chart.showLoading('Simulating Ajax ...');
setTimeout(function () {
chart.hideLoading();
chart.addSeriesAsDrilldown(e.point, series);
}, 1000);
}
}
}
},
title: {
text: 'Async drilldown'
},
xAxis: {
type: 'category'
},
legend: {
enabled: false
},
plotOptions: {
series: {
borderWidth: 0,
dataLabels: {
enabled: true,
}
}
},
series: [{
name: 'Things',
colorByPoint: true,
data: [{
name: 'Animals',
y: 5,
drilldown: true
}, {
name: 'Fruits',
y: 2,
drilldown: true
}, {
name: 'Cars',
y: 4,
drilldown: true
}]
}],
drilldown: {
series: []
}
})
Run Code Online (Sandbox Code Playgroud)
});
Paw*_*Fus 10
你的例子:http://jsfiddle.net/S3j35/
使用e.point.name以确定点击了哪个点,你从服务器需要哪些数据.当AJAX出现时,只需添加新数据系列:
drilldown: function (e) {
if (!e.seriesOptions) {
// e.point.name is info which bar was clicked
chart.showLoading('Simulating Ajax ...');
$.get("path/to/place.html?name=" + e.point.name, function(data) {
/***
where data is this format:
data = {
name: 'Cars',
data: [
['Toyota', 1],
['Volkswagen', 2],
['Opel', 5]
]
}
***/
chart.hideLoading();
chart.addSeriesAsDrilldown(e.point, data);
});
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9614 次 |
| 最近记录: |