封装好的方法:
- //饼状图
- function piechart(id, title, series, drilldownSeries)
- {
- $(id).highcharts({
- chart: {
- plotBackgroundColor: null,
- plotBorderWidth: null,
- plotShadow: false,
- type:'pie'
- },
- title: {
- text: title,
- style: "font-size:12px;"
- },
- tooltip: {
- //pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
- pointFormat: '<span style="color:{point.color}">事故数:{point.y}<br/>占比:{point.percentage:.2f}%</span>'
- },
- plotOptions: {
- pie: {
- //allowPointSelect: true,
- //cursor: 'pointer',
- dataLabels: {
- enabled: false
- },
- showInLegend: false
- }
- },
- credits: {
- enabled: false
- },
- series: series,
- drilldown: drilldownSeries
- });
- }
复制代码
调用:
- $(function () {
- Highcharts.setOptions({
- lang: {
- drillUpText: '<< 返回 {series.name}'
- }
- });
- piechart('#accidentstatus', '事故状态', [{
- colorByPoint: true,
- name: '事故状态',
- data: [
- {
- name: '未结案',
- y: 620,
- drilldown: 'animals'
- },
- {
- name: '已结案',
- y: 9514,
- drilldown: 'fruits'
- }
- ]
- }], {
- drillUpButton: {
- relativeTo: 'spacingBox',
- position: {
- y: 0,
- x: 0
- },
- theme: {
- fill: 'white',
- 'stroke-width': 1,
- stroke: 'silver',
- r: 0,
- states: {
- hover: {
- fill: '#bada55'
- },
- select: {
- stroke: '#039',
- fill: '#bada55'
- }
- }
- }
- },
- series: [{
- id: 'animals',
- data: [
- ['Cats', 4],
- ['Dogs', 2],
- ['Cows', 1],
- ['Sheep', 2],
- ['Pigs', 1]
- ]
- }, {
- id: 'fruits',
- data: [
- ['Apples', 4],
- ['Oranges', 2]
- ]
- }]
- });
- });
复制代码
注意!!!!!如果,点击没有效果,就是缺少引用!!!
记得引用/js/modules/drilldown.js 这个玩意。
|