2 * Copyright 2016-2017, CMCC Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 // draw the chart by performance datas
17 function drawPerformanceChart() {
19 var titleText = document.getElementById("tableTitleText").innerHTML;
20 var subTitleText = "subTitleText";
21 var chartDataList = [];
22 var resourceNameList = [];
26 var tableObj = document.getElementById("ict_pm_data");
27 if (tableObj == null || tableObj.rows.length < 1) {
31 // distinguish between chart types
32 var ratioType = tableObj.rows[0].cells[5].innerText;
33 if (ratioType.indexOf("CPU") > -1) {
35 subTitleText = "CPU USE RATIO";
36 } else if (ratioType.indexOf("RAM") > -1) {
38 subTitleText = "RAM USE RATIO";
39 } else if (ratioType.indexOf("VOLUME") > -1) {
40 chartType = "FILESYSTEM";
41 subTitleText = "LOGIC VOLUME FILESYSTEM USE RATIO";
42 } else if (ratioType.indexOf("NIC") > -1) {
44 subTitleText = "ERROR PACKET RATIO BY ONE COLLECT-PERIOD (SEND AND RECEIVED)";
49 // collect datas for chart horizontal axis
50 for (var i = 1; i < tableObj.rows.length; i++) {
51 var strTime = tableObj.rows[i].cells[0].innerText;
53 if (timeList.length == 0) {
54 // push the first start time into the x-axis
55 timeList.push(strTime);
57 // push the start times into the x-axis and sort them
58 for (var j = 0; j < timeList.length; j++) {
59 if (timeList[j] == strTime) {
61 } else if (timeList[j] > strTime) {
62 timeList.splice(j, 0, strTime);
64 } else if (j + 1 == timeList.length && timeList[j] < strTime) {
65 timeList.push(strTime);
72 // create chart resources
73 for (var i = 1; i < tableObj.rows.length; i++) {
74 var strTime = tableObj.rows[i].cells[0].innerText;
75 var ratioIndex = getListIndex(timeList, strTime);
79 if (chartType == "CPU" || chartType == "RAM") {
80 strName = tableObj.rows[i].cells[4].innerText;
81 strRatio = tableObj.rows[i].cells[5].innerText;
82 } else if (chartType == "FILESYSTEM") {
83 strName = tableObj.rows[i].cells[4].innerText + "(" + tableObj.rows[i].cells[6].innerText + ")";
84 strRatio = tableObj.rows[i].cells[9].innerText;
85 } else if (chartType == "NIC") {
86 strName = tableObj.rows[i].cells[4].innerText + "(" + tableObj.rows[i].cells[5].innerText + ")";
87 strRatio = parseFloat(tableObj.rows[i].cells[10].innerText) + parseFloat(tableObj.rows[i].cells[11].innerText);
90 if (chartDataList.length == 0) {
91 // create the first chart resource and push it into the chartlist
92 insertChartDataList(chartDataList, strName, strRatio, ratioIndex);
94 // update the chart resources which exist in chartlist
96 for (var j = 0; j < chartDataList.length; j++) {
97 if (chartDataList[j].name == strName) {
98 chartDataList[j].data[ratioIndex] = strRatio;
104 // create a new chart resource and push it into the chartlist
106 insertChartDataList(chartDataList, strName, strRatio, ratioIndex);
111 for (var i = 0; i < chartDataList.length; i++) {
112 // complete length of datalist for each chart resource
113 if (chartDataList[i].data.length < timeList.length) {
114 chartDataList[i].data[timeList.length - 1] = "";
117 // create the name list of chart resources
118 resourceNameList.push(chartDataList[i].name);
121 // initialize the chart
122 var dom = document.getElementById("chartCanvasDiv");
123 var myChart = echarts.init(dom);
126 // set the chart by collected chart resources
130 subtext: subTitleText,
137 data:resourceNameList,
146 magicType: {type: ['line', 'bar']},
154 data : timeList.map(function (str) {
155 return str.replace(' ', '\n')
159 name : 'percentage(%)',
162 series: chartDataList
165 // draw the performance chart of all resources
166 if (option && typeof option === "object") {
167 myChart.setOption(option, true);
171 // define the struct of chart resource
172 function chartData() {
179 // create a new chart resource and push it into the chartlist
180 function insertChartDataList(chartDataList, name, data, dataIndex) {
181 var cd = new chartData();
183 cd.data[dataIndex] = data;
184 chartDataList.push(cd);
187 // return the index of the specified element in the list
188 function getListIndex(list, data) {
190 for (var i = 0; i < list.length; i++) {
191 if (list[i] == data) {