YII2框架中统计图插件highcharts所有属性和方法

Highcharts的基本属性和方法详解 

标签:jquery插件 /Highcharts

官方API:http://www.hcharts.cn/api/index.php

Highcharts 是一个用纯JavaScript编写的一个图表库, 能够很简单便捷的在web网站或是web应用程序添加有交互性的图表,并且免费提供给个人学习、个人网站和非商业用途使用。

目前HighCharts支持的图表类型有曲线图、区域图、柱状图、饼状图、散状点图和综合图表。

HighCharts界面美观,由于使用JavaScript编写,所以不需要像Flash和Java那样需要插件才可以运行,而且运行速度快。另外HighCharts还有很好的兼容性,能够完美支持当前大多数浏览器。

下面给出实例并详解分析他们:

[javascript]  view plain  copy
  1. <script type="text/javascript" src="js/jquery.min.js"></script>    
  2. <script type="text/javascript" src="js/highcharts.js"></script>     
  3. <script type="text/javascript">    
  4. var chart;    
  5. $(document).ready(function() {    
  6.     chart = new Highcharts.Chart({    
  7.         chart: {    
  8.             renderTo: 'container',//设置显示图表的容器    
  9.             type: 'line',//设置图表样式,可以为line,spline, scatter, splinearea bar,pie,area,column    
  10. //          defaultSeriesType: 'column', //图表的默认样式    
  11. //          margin:[21, 23, 24, 54],//整个图表的位置(上下左右的空隙)    
  12.             marginRight: 200,//右边间距    
  13.             marginBottom: 25//底部间距/空隙    
  14. //          inverted: false,//可选,控制显示方式,默认上下正向显示    
  15. //          shadow:true,//外框阴影    
  16. //          backgroundColor:"#FFF",    
  17. //          animation:true,    
  18. //          borderColor:"#888",    
  19. //          borderRadius:5,    
  20. //          borderWidth:1,    
  21. //          ignoreHiddenSeries:true,    
  22. //          reflow:true,    
  23. //          plotBorderWidth:1,    
  24. //          alignTicks:true    
  25.         },    
  26.         labels:{//在报表上显示的一些文本    
  27.             items:[{    
  28.                 html:'本图表数据有误,仅用于说明相应的属性',    
  29.                 style:{left:'100px',top:'60px'}    
  30.             }, {    
  31.                 html:'http://www.highcharts.com/demo',    
  32.                 style:{left:'100px',top:'100px'}    
  33.             }]    
  34.         },    
  35.         credits:{//右下角的文本    
  36.             enabled: true,    
  37.             position: {//位置设置    
  38.                 align: 'right',    
  39.                 x: -10,    
  40.                 y: -10    
  41.             },    
  42.             href: "http://www.highcharts.com",//点击文本时的链接    
  43.             style: {    
  44.                 color:'blue'    
  45.             },    
  46.             text: "Highcharts Demo"//显示的内容    
  47.         },    
  48. //        plotOptions:{//绘图线条控制    
  49. //            spline:{    
  50. //                allowPointSelect :true,//是否允许选中点    
  51. //                animation:true,//是否在显示图表的时候使用动画    
  52. //                cursor:'pointer',//鼠标移到图表上时鼠标的样式    
  53. //                dataLabels:{    
  54. //                   enabled :true,//是否在点的旁边显示数据    
  55. //                    rotation:0    
  56. //                },    
  57. //                enableMouseTracking:true,//鼠标移到图表上时是否显示提示框    
  58. //                events:{//监听点的鼠标事件    
  59. //                    click: function() {    
  60. //                    }    
  61. //                },    
  62. //                marker:{    
  63. //                    enabled:true,//是否显示点    
  64. //                   radius:3,//点的半径    
  65. //                      fillColor:"#888"    
  66. //                    lineColor:"#000"    
  67. //                    symbol: 'url(http://highcharts.com/demo/gfx/sun.png)',//设置点用图片来显示    
  68. //                    states:{    
  69. //                        hover:{    
  70. //                            enabled:true//鼠标放上去点是否放大    
  71. //                                                    },    
  72. //                        select:{    
  73. //                            enabled:false//控制鼠标选中点时候的状态    
  74. //                        }    
  75. //                    }    
  76. //               },    
  77. //                states:{    
  78. //                    hover:{    
  79. //                        enabled:true,//鼠标放上去线的状态控制    
  80. //                        lineWidth:3    
  81. //                    }    
  82. //                },    
  83. //                stickyTracking:true,//跟踪    
  84. //                visible:true,    
  85. //                lineWidth:2//线条粗细    
  86. //                pointStart:100,    
  87. //            }    
  88. //        },    
  89.    
  90.         title: {    
  91.             text: 'Monthly Average Temperature',//标题    
  92.             x: -20 //center设置标题的位置    
  93.         },    
  94.         subtitle: {    
  95.             text: 'Source: WorldClimate.com',//副标题    
  96.             x: -20//副标题位置    
  97.         },    
  98.         xAxis: {//横轴的数据    
  99.             categories: ['Jan''Feb''Mar''Apr''May''Jun',    
  100.                 'Jul''Aug''Sep''Oct''Nov''Dec']    
  101. //          lineWidth:1,//纵轴一直为空所对应的轴,即X轴    
  102. //          plotLines: [{//一条竖线    
  103. //               color: '#FF0000',    
  104. //               width: 2,    
  105. //               value: 5.5    
  106. //           }]    
  107. //          labels: {//设置横轴坐标的显示样式    
  108. //              rotation: -45,//倾斜度    
  109. //              align: 'right',    
  110. //              style: {    
  111. //                   font: 'normal 13px Verdana, sans-serif'    
  112. //                   color: 'white'    
  113. //              }    
  114. //          }    
  115.    
  116.         },    
  117.         yAxis: {    
  118. //          tickInterval: 200,  //自定义刻度    
  119. //          max:1000,//纵轴的最大值    
  120. //          min: 0,//纵轴的最小值    
  121.             title: {//纵轴标题    
  122.                 text: '百分数'    
  123.             },    
  124.             labels : {    
  125.                 formatter : function() {//设置纵坐标值的样式    
  126.                  return this.value + '%';    
  127.                 }    
  128.                },     
  129.             plotLines: [{    
  130.                 value: 0,    
  131.                 width: 1,    
  132.                 color: '#808080'    
  133.             }]    
  134.         },    
  135.         tooltip: {//鼠标移到图形上时显示的提示框    
  136.             formatter: function() {    
  137.                     return '<b>'this.series.name +'</b><br />'+    
  138.                     this.x +': 'this.y +'°C';    
  139.             }    
  140. //          crosshairs:[{//控制十字线    
  141. //              width:1,    
  142. //              color:"#CCC",    
  143. //              dashStyle:"longdash"    
  144. //          }    
  145.    
  146.         },    
  147.         legend: {//方框所在的位置(不知道怎么表达),(右边的表说明)    
  148.             layout: 'vertical',    
  149.             align: 'right',    
  150.             verticalAlign: 'top',    
  151.             x: -10,    
  152.             y: 100,    
  153.             borderWidth: 0    
  154.         },    
  155.         series: [{//以下为纵轴数据    
  156.             name: 'Tokyo',    
  157.             data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]    
  158.         }, {    
  159.             name: 'New York',    
  160.             data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]    
  161.         }, {    
  162.             name: 'Berlin',    
  163.             data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]    
  164.         }, {    
  165.             name: 'London',    
  166.             data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]    
  167.         }]    
  168.     });    
  169. });    
  170. </script>    
  171.    
  172. <body>    
  173. <div id="container" ></div>    
  174. </body></span>  

一.chart的部分相关属性说明

[javascript]  view plain  copy
  1. renderTo: 'container',      //图表的页面显示容器(也就是要显示到的div)  
  2. defaultSeriesType: 'line',  //图表类型(line、spline、scatter、splinearea、bar、pie、area、column)  
  3. marginRight: 50,            //上下左右空隙(图表跟图框之间)  
  4. marginBottom: 60,           //下面空隙如果不够大,图例说明有可能看不到  
  5. plotBackgroundImage: '../graphics/skies.jpg'//(图表的)背景图片  
  6. plotBackgroundColor:        //背景颜色  
  7. width: 1000,                //图框(最外层)宽(默认800)  
  8. height: 500,                //图框高(默认500)   
  9. backgroundColor: "red"      //图框的背景颜色  
  10. borderColor: "red"          //图框的边框颜色  
  11. borderRadius: 5,            //图框的圆角大小  
  12. borderWidth: 9,             //图框的边框大小  
  13. inverted: false,            //(使图)倒置  
  14. plotBorderColor: "red",     //图表的边框颜色  
  15. plotBorderWidth: 0,         //图表的边框大小  
  16. plotShadow: false,          //图表是否使用阴影效果  
  17. reflow: false,     
  18. shadow:true                 //图框是否使用阴影  
  19. showAxes: false,            //是否最初显示轴  
  20. spacingTop: 100,            //图表上方的空白  
  21. spacingRight: 10,  
  22. spacingBottom: 15,  
  23. spacingLeft: 10,  
  24. colors: [...]                 //图上线。。的颜色</span>  
二. credits的部分相关属性说明
[javascript]  view plain  copy
  1. credits:  //设置右下角的标记。highchart.com (这个也可以在highcharts.js里中修改)  
  2. {      
  3.     //enabled: true,      //是否显示  
  4.     position: {           //显示的位置                     
  5.         align: 'left',         
  6.         x: 10                             
  7.     },  
  8.     text: "xoyo.com",           //显示的文字  
  9.     style:{                     //样式  
  10.         cursor: 'pointer',  
  11.         color: 'red',  
  12.         fontSize: '20px'  
  13.     },  
  14.     href: 'http://www.xoyo.com', //路径  
  15. },</span>  

三. title的部分相关属性说明

[javascript]  view plain  copy
  1. title: //标题  
  2. {   
  3.     text: '月份平均温度',  
  4.     x: -20,                  //center //水平偏移量   
  5.     y: 100                   //y:垂直偏移量  
  6.     align: 'right'         //水平方向(left, right, bottom, top)  
  7.     floating: true,          //是否浮动显示  
  8.     margin: 15,  
  9.     style: ,                 //样式  
  10.     verticalAlign: "left"    //垂直方向(left, right, bottom, top)  
  11. },</span>  

四. xAxis或者YAxis的部分相关属性说明

[javascript]  view plain  copy
  1. categories: ['一月''二月'],  
  2. //allowDecimals: false  
  3. //alternateGridColor: 'red'       //在图表中相隔出现纵向的颜色格栅  
  4. //dateTimeLabelFormats: ,  
  5. //endOnTick: false,               //是否显示控制轴末端的一个cagegories出来  
  6. //events: {  
  7. //setExtremes:  
  8. //},  
  9. //gridLineColor: "red",           //纵向格线的颜色  
  10. //gridLineDashStyle: Solid        //纵向格栅线条的类型  
  11. //gridLineWidth: 5,               //纵向格线的的大小  
  12. //id: null,  
  13. //labels: {  //X轴的标签(下面的说明)  
  14.     //align: "center",              //位置  
  15.     //enabled: false,               //是否显示  
  16.     //formatter: ,  
  17.     //rotation: 90,                 //旋转,效果就是影响标签的显示方向  
  18.     //staggerLines: 4,              //标签的交错显示(上、下)  
  19.     //step: 2,                      //标签的相隔显示的步长  
  20.     //style:{},  
  21.     //x: 100,                     //偏移量,默认两个都是0,  
  22.     //y: 40  
  23.   
  24. //},  
  25. //lineColor: "red",               //X轴的颜色  
  26. //lineWidth: 5,                   //X轴的宽度  
  27. //linkedTo:1,  
  28. //opposite: true                  //是否把标签显示到对面  
  29. //max: 12,                        //显示的最大值  
  30. //maxPadding: 6,  
  31. //maxZoom: 1,  
  32. //min: 10,                        //显示的最小值  
  33. //minorGridLineColor: 'red',        //副格线的颜色  
  34. //minorGridLineDashStyle: 'blod', //副格线的的颜色  
  35. //minorGridLineWidth: 50,         //副格线的宽度  
  36. //minorTickColor: #A0A0A0,        //没有看出效果  
  37. minorTickInterval:3,               //副标记的间隔  
  38. //minorTickLength: 10,             //副标记的长度  
  39. //minorTickPosition: 'inside',     //副标记的位置  
  40. //minorTickWidth: 5,               //副标记的宽  
  41. //minPadding: 0.01,  
  42. //offset: 0,                       //坐标轴跟图的距离  
  43. //plotBands: //使某数据块显示不同的效果      
  44. //plotLines: [{         //标线属性  
  45.     //value: 0,      //值为0的标线  
  46. //}],          
  47. //tickmarkPlacement: "on",   //标记(文字)显示的位置,on表示在正对位置上。  
  48. //reversed: true,            //是否倒置  
  49. //showFirstLabel: false,     //第一个标记的数值是否显示  
  50. //startOfWeek: 2,  
  51. //tickColor: 'blue',         //标记(坐标的记号)的颜色  
  52. //tickInterval: 20,          //标记(坐标的记号)的步长  
  53. //tickLength: 5,  
  54. //tickmarkPlacement: "on",  
  55. //tickPixelInterval: 1000,   //两坐标之间的宽度  
  56. //tickPosition: "inside",    //坐标标记的方向  
  57. //title: {                   //设置坐标标题的相关属性  
  58.     //margin: 40,  
  59.     //rotation: 90,  
  60.     //text: "Y-values",  
  61.     //align: "middle",  
  62.     //enabled: "middle",  
  63.     //style: {color: 'red'}  
  64. //},  
  65. //type: "linear"</span>  


五.tooltip的部分相关属性说明

[javascript]  view plain  copy
  1. tooltip: //提示框设置  
  2. {        
  3.     formatter: function() {  //格式化提示框的内容样式  
  4.     return '<b>'this.series.name +'</b><br />'+  
  5.             this.x +': 'this.y +'°C';  
  6.     },                         
  7.     backgroundColor: '#CCCCCC',   //背景颜色  
  8.     //borderColor: '#FCFFC5'      //边框颜色  
  9.     //borderRadius: 2             //边框的圆角大小  
  10.     borderWidth: 3,               //边框宽度(大小)  
  11.     //enabled: false,             //是否显示提示框  
  12.     //shadow: false,              //提示框是否应用阴影,没有看出明显效果  
  13.     //shared: true,               //当打开这个属性,鼠标几个某一区域的时候,如果有多条线,所有的线上的据点都会有响应(ipad)  
  14.     //snap: 0,                    //没有看出明显效果  
  15.     crosshairs: {                 //交叉点是否显示的一条纵线  
  16.         width: 2,  
  17.         color: 'gray',  
  18.        dashStyle: 'shortdot'  
  19.     }  
  20.     style: {  //提示框内容的样式  
  21.         color: 'white',  
  22.         padding: '10px',    //内边距 (这个会常用到)  
  23.         fontSize: '9pt',              
  24.     }  
  25. },</span>  

六.legend(图例说明)的部分相关属性说明

[javascript]  view plain  copy
  1. legend: //图例说明  
  2.  {     
  3.      //layout: 'vertical',   //图例说明布局(垂直显示,默认横向显示)  
  4.      align: 'center',        //图例说明的显示位置  
  5.      //verticalAlign: 'top', //纵向的位置  
  6.      //x: 250,                 //偏移量   
  7.      //y: 0,                 
  8.      borderWidth: 1,            //边框宽度  
  9.      //backgroundColor: 'red'   //背景颜色  
  10.      borderColor: 'red',  
  11.      //borderRadius             //边框圆角  
  12.      //enabled: false          //是否显示图例说明  
  13.      //floating:true           //是否浮动显示(效果就是会不会显示到图中)  
  14.      //itemHiddenStyle: {color: 'red'},  
  15.      //itemHoverStyle: {color: 'red'}   //鼠标放到某一图例说明上,文字颜色的变化颜色  
  16.      //itemStyle:  {color: 'red'}   //图例说明的样式  
  17.      //itemWidth:                   //图例说明的宽度  
  18.      //labelFormatter: function() { return this.value}       //默认(return this.name)  
  19.      //lineHeight: 1000             //没看出明显效果  
  20.      //margin: 20  
  21.      //reversed:true                //图例说明的顺序(是否反向)  
  22.      //shadow:true                  //阴影  
  23.      //style: {color:'black'}  
  24.      //symbolPadding: 100           //标志(线)跟文字的距离  
  25.      //symbolWidth: 100             //标志的宽  
  26.      //width:100  
  27.  },</span>  

七. plotOptions的部分修改属性说明

[javascript]  view plain  copy
  1. plotOptions:  
  2.  {    
  3.      column: //柱形图  
  4.      {  
  5.          //pointPadding: 0.2,  
  6.          //borderWidth: 1,               //柱子边框的大小  
  7.          //borderColor: "red",           //柱子边框的颜色  
  8.          //borderRadius: 180,            //柱子两端的圆角的半径  
  9.          //colorByPoint: true,           //否应该接受每系列的一种颜色或每点一种颜色  
  10.          groupPadding: 0,                //每一组柱子之间的间隔(会影响到柱子的大小)  
  11.          //minPointLength: 0,            //最小数据值那一条柱子的长度(如果是0,可能看不到,可以设置出来)  
  12.          //pointPadding: 0.1,            //柱子之间的间隔(会影响到柱子的大小)  
  13.          //pointWidth: 2,                //柱子的大小(会影响到柱子的大小)  
  14.          //allowPointSelect: false,   
  15.          //animation: true,              //图形出来时候的动画  
  16.          //color: 'red',                 //柱子的颜色  
  17.          //connectNulls: false,          //连接图表是否忽略零点(如线形图,数据为0是是否忽略)  
  18.          //cursor: '',                   //游标  
  19.          //dashStyle: null,  
  20.          dataLabels: { //图上是否显示数据标签  
  21.          //enabled: true,  
  22.          align: "center",  
  23.          //color: 'red',  
  24.          formatter: function()   
  25.          {  
  26.              return this.y + 'mm'  
  27.          },  
  28.          rotation: 270,  
  29.          //staggerLines: 0,  
  30.          //step: ,  
  31.          //style: ,  
  32.          //x: 0,  
  33.          //y: -6  
  34.          },  
  35.          //enableMouseTracking:   
  36.          events: {    //事件  
  37.          click: function(event)  
  38.          {  
  39.              alert(this.name);  
  40.          },  
  41.          //checkboxClick: ,  
  42.          //hide: ,  
  43.          //legendItemClick: ,  
  44.          //mouseOver: ,  
  45.          //mouseOut: ,  
  46.          //show:  
  47.          },  
  48.          //id: null,  
  49.          //lineWidth: 20,  
  50.          //marker: {  //图例说明上的标志  
  51.          //enabled: false  
  52.          //},  
  53.          point: {     //图上的数据点(这个在线形图可能就直观)  
  54.          events: {  
  55.              click: function()   
  56.              {  
  57.              alert(this.y);  
  58.              },  
  59.              //mouseOver: ,  
  60.              //mouseOut: ,  
  61.              //remove: ,  
  62.              //select: ,  
  63.              //unselect: ,  
  64.              //update:  
  65.              }  
  66.          },  
  67.          //pointStart: 0,     //显示图数据点开始值  
  68.          //pointInterval: 1,  //显示图数据点的间隔  
  69.          //selected: false,  
  70.          //shadow: true,  
  71.          //showCheckbox: true,  //是否显示(图例说明的)复选框  
  72.          //showInLegend: false, //是否显示图例说明  
  73.          //stacking: 'percent', //是否堆积  
  74.          states:   
  75.          {  
  76.                          hover:   
  77.              {  
  78.                              //brightness: 0.1,  
  79.                              enabled: true,    //图上的数据点标志是否显示  
  80.                              //lineWidth: 2,    //没看出效果  
  81.                              marker:   
  82.              {  
  83.                                  //states: ,  
  84.                                  //enabled: true,         //数据点标志是否显示  
  85.                                  //fillColor: null,       //数据点标志填充的颜色  
  86.                                  //lineColor: "#FFFFFF",  //数据点标志线的颜色  
  87.                                  //lineWidth: 0,          //数据点标志线的大小  
  88.                                  //radius: 45,            //数据点标志半径  
  89.                                  //symbol: 'triangle'//'url(http://highcharts.com/demo/gfx/sun.png)' //数据点标志形状(triangle三角形,或者用图片等等)  
  90.                              }  
  91.                          }  
  92.                   },  
  93.           //stickyTracking: true,  //轨道粘性 (例如线图,如果这个设置为否定,那就必须点到数据点才有反应)  
  94.           //visible: true,         //设置为false就不显示图  
  95.           //zIndex: null           //层级  
  96.  },</span> 

  97.  
另外的示例图:




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值