JS插件实现图表显示(曲线图表、柱形图表、饼状图表)

先看效果图:


代码如下:

  1. <span style="font-size:14px;"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <title>图表统计</title>  
  5.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  6. <script type="text/javascript" src="JS/jquery.js"></script>  
  7. <script type="text/javascript" src="highcharts/highcharts.js"></script>  
  8. <script type="text/javascript">  
  9.         var chart;  
  10.         $(document).ready(function () {  
  11.             //曲线图初始化  
  12.             chart = new Highcharts.Chart({  
  13.                 chart: {  
  14.                     renderTo: 'container1',  
  15.                     type: 'line',  
  16.                     marginRight: 220,  
  17.                     marginBottom: 25  
  18.                 },  
  19.                 title: {  
  20.                     text: '数据曲线图表',  
  21.                     x: -20 //center  
  22.                 },  
  23.                 subtitle: {  
  24.                     text: 'jqddsjfx',  
  25.                     x: -20  
  26.                 },  
  27.                 xAxis: {  
  28.                     categories: ['02年', '02年', '02年', '04年', '05年', '06年',  
  29.                 '07年', '08年', '09年', '20年', '22年', '22年']  
  30.                 },  
  31.                 yAxis: {  
  32.                     title: {  
  33.                         text: '数据'  
  34.                     },  
  35.                     plotLines: [{  
  36.                         value: 0,  
  37.                         width: 2,  
  38.                         color: '#808080'  
  39.                     }]  
  40.                 },  
  41.                 tooltip: {  
  42.                     formatter: function () {  
  43.                         return '<b>' + this.series.name + '</b><br/><br/>' +  
  44.                     this.x + ': ' + this.y + '单位';  
  45.                     }  
  46.                 },  
  47.                 legend: {  
  48.                     layout: 'vertical',  
  49.                     align: 'right',  
  50.                     verticalAlign: 'top',  
  51.                     x: -20,  
  52.                     y: 200,  
  53.                     borderWidth: 0  
  54.                 },  
  55.                 series: [{  
  56.                     name: '用户1',  
  57.                     data: [22, 22, 95, 245, 282, 225, 252, 265, 222, 282, 229, 96]  
  58.                 }, {  
  59.                     name: '用户2',  
  60.                     data: [02, 08, 57, 222, 270, 220, 248, 242, 202, 242, 86, 25]  
  61.                 }, {  
  62.                     name: '用户3',  
  63.                     data: [9, 06, 25, 84, 225, 270, 286, 279, 242, 90, 29, 20]  
  64.                 }, {  
  65.                     name: '用户4',  
  66.                     data: [29, 42, 57, 85, 229, 252, 270, 266, 242, 202, 66, 48]  
  67.                 }]  
  68.             });  
  69.   
  70.             //柱形图初始化  
  71.             chart = new Highcharts.Chart({  
  72.                 chart: {  
  73.                     renderTo: 'container2',  
  74.                     type: 'column'  
  75.                 },  
  76.                 title: {  
  77.                     text: '数据柱形图表'  
  78.                 },  
  79.                 subtitle: {  
  80.                     text: 'jqddsjfx'  
  81.                 },  
  82.                 xAxis: {  
  83.                     categories: [  
  84.                 '01年',  
  85.                 '02年',  
  86.                 '03年',  
  87.                 '04年',  
  88.                 '05年',  
  89.                 '06年',  
  90.                 '07年',  
  91.                 '08年',  
  92.                 '09年',  
  93.                 '10年',  
  94.                 '11年',  
  95.                 '12年'  
  96.             ]  
  97.                 },  
  98.                 yAxis: {  
  99.                     min: 0,  
  100.                     title: {  
  101.                         text: '数据'  
  102.                     }  
  103.                 },  
  104.                 legend: {  
  105.                     layout: 'vertical',  
  106.                     backgroundColor: '#FFFFFF',  
  107.                     align: 'left',  
  108.                     verticalAlign: 'top',  
  109.                     x: 100,  
  110.                     y: 70,  
  111.                     floating: true,  
  112.                     shadow: true  
  113.                 },  
  114.                 tooltip: {  
  115.                     formatter: function () {  
  116.                         return '' +  
  117.                     this.x + ': ' + this.y + ' 单位';  
  118.                     }  
  119.                 },  
  120.                 plotOptions: {  
  121.                     column: {  
  122.                         pointPadding: 0.2,  
  123.                         borderWidth: 0  
  124.                     }  
  125.                 },  
  126.                 series: [{  
  127.                     name: '用户1',  
  128.                     data: [499, 715, 1064, 1292, 1440, 1760, 1356, 1485, 2164, 1941, 956, 544]  
  129.   
  130.                 }, {  
  131.                     name: '用户2',  
  132.                     data: [836, 788, 985, 934, 1060, 845, 1050, 1043, 912, 835, 1066, 923]  
  133.   
  134.                 }, {  
  135.                     name: '用户3',  
  136.                     data: [489, 388, 393, 414, 470, 483, 590, 596, 524, 652, 593, 512]  
  137.   
  138.                 }, {  
  139.                     name: '用户4',  
  140.                     data: [424, 332, 345, 397, 526, 755, 574, 604, 476, 391, 468, 511]  
  141.   
  142.                 }]  
  143.             });  
  144.   
  145.         //饼状图初始化  
  146.         chart = new Highcharts.Chart({  
  147.             chart: {  
  148.                 renderTo: 'container3',  
  149.                 plotBackgroundColor: null,  
  150.                 plotBorderWidth: null,  
  151.                 plotShadow: false  
  152.             },  
  153.             title: {  
  154.                 text: '数据饼状图表'  
  155.             },  
  156.             tooltip: {  
  157.                 formatter: function () {  
  158.                     return '<b>' + this.point.name + '</b>: ' + this.percentage.toFixed(2) + ' %';  
  159.                 }  
  160.             },  
  161.             plotOptions: {  
  162.                 pie: {  
  163.                     allowPointSelect: true,  
  164.                     cursor: 'pointer',  
  165.                     dataLabels: {  
  166.                         enabled: true,  
  167.                         color: '#000000',  
  168.                         connectorColor: '#000000',  
  169.                         formatter: function () {  
  170.                             return '<b>' + this.point.name + '</b>: ' + this.percentage.toFixed(2) + ' %';  
  171.                         }  
  172.                     }  
  173.                 }  
  174.             },  
  175.             series: [{  
  176.                 type: 'pie',  
  177.                 name: 'pie',  
  178.                 data: [  
  179.                 ['圆通快递', 55.0],  
  180.                 ['中通快递', 26.8],  
  181.                 {  
  182.                     name: 'EMS',  
  183.                     y: 12.8,  
  184.                     sliced: true,  
  185.                     selected: true  
  186.                 },  
  187.                 ['申通快递', 7.5]  
  188.             ]  
  189.             }]  
  190.         });  
  191.     });  
  192. </script>  
  193. </head>  
  194. <body>  
  195. <div style="margin: 0 2em">  
  196.         <div id="container1" style="min-width: 400px; height: 400px; margin: 0 auto"></div><br />  
  197.         <div id="container2" style="min-width: 400px; height: 400px; margin: 0 auto"></div><br />  
  198.         <div id="container3" style="min-width: 400px; height: 400px; margin: 0 auto"></div>  
  199.     </div>  
  200. </body>  
  201. </html></span>  
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值