JS 封装类
function HighchartsObj(id, type) { var that = this; this.options = { chart : { renderTo : id, type : type, style : { cursor : 'pointer' }, events : { click : function(e) { // console.log(that.extra); var params = that.extra.split(','); if (null != params && 5 === params.length) { toIndiPage(params[0], params[1], params[2], params[3], params[4]); } } } }, credits : { // 隐藏版权 enabled : false }, title : { // 隐藏标题 text : null }, legend : { // 隐藏图列 enabled : false }, tooltip : { pointFormat : '{series.name}:<b>{point.y}</b>' }, xAxis : { labels : { // X坐标隐藏 enabled : false }, categories : [] }, yAxis : { title : { // 隐藏Y轴文本 text : null } }, series : [] }; this.highcharts = null; this.extra = null; } HighchartsObj.prototype = { setCategories : function(categories) { if (!this.isArrayType(categories)) { alert('not array'); return; } this.options.xAxis.categories = categories; }, setSeries : function(series) { if (!this.isArrayType(series)) { alert('not array'); return; } var data = []; for ( var i = series.length - 1; i >= 0; i--) { for ( var j = 0, len = series[i]['data'].length; j < len; j++) { var val = series[i]['data'][j]; if ('' === val || null === val) { val = null; } else { val = Number(val); } data.push(val); } var minVal = Math.min.apply(null, data); var maxVal = Math.max.apply(null, data); // console.log(minVal + '==========' + maxVal); series[i]['data'] = $.map(data, function(val, key) { // console.log(val + '--------' + key); if (val === minVal) { return { y : val, marker : { radius : 3 } }; } else if (val === maxVal) { return { y : val, marker : { radius : 5 } }; } return val; }); } this.options.series = series; }, createObj : function() { this.highcharts = new Highcharts.Chart(this.options); }, isArrayType : isType('Array'), isNumberType : isType('Number'), isStringType : isType('String') } // 判断类型 function isType(type) { return function(obj) { return Object.prototype.toString.call(obj) === '[object ' + type + ']'; } }