1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
var ICT_Line_C3 = function (placeholderC3, seriesNames, colors) {
var xkeys = {"x": "x", "value": []};
//��ʼ�����
var config = {};
config.bindto = '#' + placeholderC3;
config.data = {};
config.data.keys = xkeys;
config.data.json = [];
config.axis = {};
config.axis.x = {"type": "timeseries", "tick": {"format": "%H:%M:%S'", count: 5}};
config.axis.y = {
padding: {
left: 0,
right: 0,
},
//,inner: true
max: 100,
min: 0
};
config.axis.y.tick = {
format: function (data) {
return (data + "").substring(0, 4) + "%";
}
, values: [0, 20, 40, 60, 80, 100]
//,centered: true
//,fit: true
, outer: false
};
config.data.colors = {};
config.data.types = {};
if (!colors) {
colors = ['#ffb980', '#5ab1ef', '#b6a2de'];
}
if (seriesNames) {
for (var i = 0; i < seriesNames.length; i++) {
config.data.colors[seriesNames[i]] = colors[i];
config.data.types[seriesNames[i]] = "spline";
}
}
/* config.data.color = function(inColor, data) {
if(data.index !== undefined) {
return colors[data.index];
}
return inColor;
}; */
config.grid = {
y: {
show: true
}
}
var c3Chart = c3.generate(config);
var dataService = new function () {
var data = [];
var numDataPoints = 60;
this.loadData = function (callback, newSeriesData) {
if (data.length > numDataPoints) {
data.shift();
}
var newValue = {"x": new Date()};
for (var i = 0; i < newSeriesData.length; i++) {
newValue[newSeriesData[i].name] = newSeriesData[i].value;
}
//data.push({"x":new Date(),"data1":newSeriesData.data1,"data2":newSeriesData.data2});
data.push(newValue);
callback(data);
};
//return this;
}
return {
setC3Data: function (newSeriesData) {
var values = [];
for (var i = 0; i < newSeriesData.length; i++) {
values.push(newSeriesData[i].name);
}
xkeys.value = values;
//var dataServiceFunc = new dataService();
dataService.loadData(function (newData) {
var data = {};
data.keys = xkeys;
data.json = newData;
//data.done = DashboardICT.removeYaxisScale;
c3Chart.load(data);
//c3Chart.resize();
}, newSeriesData);
}
};
}
|