我需要创建一个带有向下钻取饼图的条形图。在所有浏览器中一切正常,但
您需要更多解释吗?
function activities(params) {
//params coming from statistics controller
var title_activities = params['title_activities'],
source_activities = params['source_activities'],
link_activities = params['link_activities'],
credits_databasis_str_activities = params['credits_databasis_str_activities'],
activities_category_names = params['activities_category_names'],
activities_category_data = params['activities_category_data'],
room_filter_name = params['room_filter_name']
var colors = Highcharts.getOptions().colors,
categories = activities_category_names,
name = 'Activities',
data = activities_category_data
function setChart(chart, options) {
chart.series[0].remove(false);
chart.xAxis[0].setCategories(options.categories, false);
chart.addSeries({
type: options.type,
name: options.name,
data: options.data,
color: options.color || colors[0]
}, false);
//chart.options.spacingRight = 35; //not working
//chart.yAxis.title = "Test"; //not working
chart.redraw();
}
var chart = new Highcharts.Chart({
chart: {
renderTo: 'activities_chart',
type: 'bar',
spacingRight: 15
//spacingLeft: 15
},
title: {
text: title_activities
},
subtitle: {
text: 'Current room: ' + room_filter_name
},
credits: {
text: "Databasis: " + credits_databasis_str_activities + " households" + " | Source: " + source_activities,
href: link_activities
},
xAxis: {
categories: categories
},
yAxis: {
title: {
text: null
},
max: 100
},
plotOptions: {
bar: {
cursor: 'pointer',
point: {
events: {
click: function() {
var drilldown = this.drilldown;
var options;
if (drilldown) { // drill down
this.series.chart.setTitle({
text: "Activities - " + drilldown.name
});
options = {
'name': drilldown.name,
'categories': drilldown.categories,
'data': drilldown.data,
'type': 'pie'
};
} else { // restore
this.series.chart.setTitle({
text: "Activities"
});
options = {
'name': name,
'categories': categories,
'data': data,
'type': 'bar'
};
}
setChart(this.series.chart, options);
}
}
}
},
pie: {
cursor: 'pointer',
point: {
events: {
click: function() {
var drilldown = this.drilldown;
var options;
if (drilldown) { // drill down
this.series.chart.setTitle({
text: "Activities - " + drilldown.name
});
options = {
'name': drilldown.name,
'categories': drilldown.categories,
'data': drilldown.data,
'type': 'pie'
};
} else { // restore
this.series.chart.setTitle({
text: "Activities"
});
options = {
'name': name,
'categories': categories,
'data': data,
'type': 'bar'
};
}
setChart(this.series.chart, options);
}
}
},
dataLabels: {
enabled: true,
color: colors[0],
connectorColor: colors[0],
distance: 15,
formatter: function() {
var label_String = this.point.name;
if (label_String.length > 16) {
label_String = label_String.substring(0,16) + "..."
};
return '<b>'+ label_String +'</b>: '+ this.y;
}
}
}
},
tooltip: {
formatter: function() {
var point = this.point,
s = ""
if (point.drilldown) {
s += this.x +':<b>'+ this.y +' % of households</b><br/>';
s += 'Click to view '+ point.category +' details';
} else {
s += point.name +':<b>'+ this.y +' times chosen</b><br/>';
s += 'Click to return to activities overview';
}
return s;
}
},
series: [{
type: 'bar',
name: name,
data: data
}],
exporting: {
enabled: false
}
});
}