zoukankan      html  css  js  c++  java
  • 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 + ']';
        }
    }
  • 相关阅读:
    C++ Vector
    难点目录
    学习图片展
    使用Github总结
    更改git bash默认的路径
    kubernetes dashboard 搭建参考
    vCenter 6.5 Appliance安装问题汇总
    转-Linux访问Windows FTP服务器中文乱码
    安装升级libpcap至1.9.0
    kubectl patch
  • 原文地址:https://www.cnblogs.com/xiaoxian1369/p/3937395.html
Copyright © 2011-2022 走看看