javascript new 对象 复用

 1 function CarPie(url, containerID, _theme) {
 2     this.dataUrl = url;
 3     this.container = containerID;
 4     this.convertedData = '';
 5     this.theme = {};
 6     if (_theme != null)
 7         this.theme = _theme;
 8 
 9 }
10 RunFaultPie.prototype = {
11     constructor: CarPie,//指向构造函数,如果不指定,则CarPie.constructor将指向object
12     //初始化执行函数,通过ajax的方式加载数据,然后调用paintMap方法完成chart绘制过程
13     initial: function (options) {
14         var defaults = {
15             type: "post",
16             data: {}
17         };
18         //console.log(options);
19         var options = $.extend(defaults, options);
20         var equ = this;
21         //console.log(this);
22         $.ajax(
23                 {
24                     type: options.type,
25                     dataType: "json",
26                     contentType: "application/json",
27                     url: this.dataUrl,
28                     data:options.data,
29                     cache: false,
30                     //async: true,
31                     beforeSend: function () {
32                         //$.jBox.tip("操作进行中,请稍候!", "loading");
33 
34                     },
35                     success: function (msg) {
36                         //console.log(msg);
37                         //this.initialMap(msg);这里不能使用this指向EquipMapHelper,因为this指向的是jquery中的ajax
38                         equ.paintChart(msg);
39                     },
40                     error: function (msg) {
41                         if (msg != null && msg.readyState != null && msg.readyState == 0) {
42                             //do nothing
43                         }
44                         else
45                             alert("error:" + msg.responseText);
46                     }
47 
48                 });
49     },
50     paintChart: function (data) {
51 
52         var myChart = echarts.init(document.getElementById(this.container));
53         option = {
54             title: {
55                 
56                 text: '故障延时分析',
57                 x: 'center',
58                 textStyle: { color: '#fff', fontWeight: 'normal', }
59             },
60             tooltip: {
61                 trigger: 'item',
62                 formatter: "{a} <br/>{b} : {c} ({d}%)"
63             },
64             legend: {
65                 orient: 'vertical',
66                 x: 'left',
67                 textStyle: { color: '#fff' },
68                 data: data.PieLegendData,
69                 show: false
70             },
71             toolbox: {
72                 show: false,
73                 feature: {
74 
75                     restore: { show: true },
76                     saveAsImage: { show: true }
77                 }
78             },
79             calculable: false,
80             color: ['#9bca62', '#fbd95d', '#5fc1de', '#ffa076', '#0083c4'],
81             series: [
82                 {
83                     name: '故障件数',
84                     type: 'pie',
85                     radius: '55%',
86                     center: ['50%', '60%'],
87 
88                     data: data.PieSeriesData
89                 }
90             ]
91         };
92 
93         myChart.setOption(option);
94     }
95 
96 }

 

posted @ 2018-03-29 16:39  八方鱼  阅读(411)  评论(0)    收藏  举报