Highcharts绘制饼图

  1. 1、使用Highcharts制作饼图的效果图如下:

    2、对应的JavaScript代码---pie-chart.js如下:

    [javascript]  view plain  copy
    1. $(function () {  
    2.     var chart;  
    3.     var totalMoney=50000  
    4.     $(document).ready(function() {  
    5.         chart = new Highcharts.Chart({  
    6.             chart: {  
    7.                 renderTo: 'pie_chart',  
    8.                 plotBackgroundColor: 'white',//背景颜色  
    9.                 plotBorderWidth: 0,  
    10.                 plotShadow: false  
    11.             },  
    12.             title: {  
    13.                 text: 'Total:$'+totalMoney,  
    14.                 verticalAlign:'bottom',  
    15.                 y:-60  
    16.             },  
    17.             tooltip: {//鼠标移动到每个饼图显示的内容  
    18.                 pointFormat: '{point.name}: <b>{point.percentage}%</b>',  
    19.                 percentageDecimals: 1,  
    20.                 formatter: function() {  
    21.                     return this.point.name+':$'+totalMoney*this.point.percentage/100;  
    22.                 }  
    23.             },  
    24.             plotOptions: {  
    25.                 pie: {  
    26.                     size:'60%',  
    27.                     borderWidth: 0,  
    28.                     allowPointSelect: true,  
    29.                     cursor: 'pointer',  
    30.                     dataLabels: {  
    31.                     enabled: true,  
    32.                     color: '#000',                        
    33.                     distance: -50,//通过设置这个属性,将每个小饼图的显示名称和每个饼图重叠  
    34.                     style: {                              
    35.                         fontSize: '10px',  
    36.                         lineHeight: '10px'  
    37.                     },  
    38.                     formatter: function(index) {      
    39.                             return  '<span style="color:#00008B;font-weight:bold">' + this.point.name + '</span>';  
    40.                        }  
    41.                   },  
    42.                  padding:20  
    43.                 }  
    44.             },  
    45.             series: [{//设置每小个饼图的颜色、名称、百分比  
    46.                 type: 'pie',  
    47.                 name: null,  
    48.                 data: [  
    49.                     {name:'Base salary',color:'#3DA9FF',y:65},  
    50.                     {name:'Health insurance',color:'#008FE0',y:20},  
    51.                     {name:'Company matched',color:'#00639B',y:10},  
    52.                     {name:'Others',color:'#CBECFF',y:5}  
    53.                 ]  
    54.             }]  
    55.         });  
    56.     });  
    57.       
    58. });  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值