Re: визуализация данных
Добавлено: Сб апр 22, 2017 6:59 pm
Такой график прикрутил, библы берёт на стороне. Зато можно увеличивать и выбирать интервалы
Код: Выделить всё
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<meta http-equiv="Pragma" content="no-cache">
<!-- Styles -->
<style>
#chartdiv {
width : 100%;
height : 500px;
}
</style>
<!-- Resources -->
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/themes/none.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<script>
//var csv is the CSV file with headers
function csvJSON(csv){
var lines=csv.split("\n");
var result = [];
for(var i=0;i<lines.length;i++){
var obj = [];
if (lines[i] == '') continue;
if (i == 0) continue;
var currentline=lines[i].split(",");
var val = [];
for(var j=0;j<currentline.length;j++){
if (j == 0) {
var myDate = new Date(currentline[j]);
} else {
val.push(Number(currentline[j]));
}
}
result.push({
date: myDate,
x1: val[0],
x2: val[1],
x3: val[2],
x4: val[3],
x5: val[4],
x6: val[5]
});
}
return result; //JavaScript object
}
function zoomChart(){
chart.zoomToIndexes(chart.dataProvider.length - 20, chart.dataProvider.length - 1);
}
jQuery.get('gotdata.css', function(data) {
data = csvJSON(data);
console.log(data);
chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "none",
"legend": {
"useGraphSettings": true
},
"dataProvider": data,
"synchronizeGrid":true,
"valueAxes": [{
"id":"v1",
"axisColor": "#FF6600",
"axisThickness": 2,
"axisAlpha": 1,
"position": "left"
}, {
"id":"v2",
"axisColor": "#FCD202",
"axisThickness": 2,
"axisAlpha": 1,
"position": "right"
}, {
"id":"v3",
"axisColor": "#B0DE09",
"axisThickness": 2,
"gridAlpha": 0,
"offset": 50,
"axisAlpha": 1,
"position": "left"
}],
"graphs": [{
"valueAxis": "v1",
"type": "smoothedLine",
"lineColor": "#FF6600",
"lineThickness": 2,
"title": "Т На Улице",
"valueField": "x1",
"fillAlphas": 0
}, {
"valueAxis": "v1",
"lineColor": "#FCD202",
"type": "smoothedLine",
"lineThickness": 2,
"title": "Т До Испарителя",
"valueField": "x2",
"fillAlphas": 0
}, {
"valueAxis": "v1",
"lineColor": "#B0DE09",
"type": "smoothedLine",
"lineThickness": 2,
"title": "T После Испарителя",
"valueField": "x3",
"fillAlphas": 0
}, {
"valueAxis": "v1",
"type": "smoothedLine",
"lineThickness": 2,
"title": "Т До Конденцатора",
"valueField": "x4",
"fillAlphas": 0
}, {
"valueAxis": "v1",
"type": "smoothedLine",
"lineThickness": 2,
"title": "Т После Конденцатора",
"valueField": "x5",
"fillAlphas": 0
}, {
"valueAxis": "v1",
"type": "smoothedLine",
"lineThickness": 2,
"title": "% Открытия ЭРВ",
"valueField": "x6",
"fillAlphas": 0
}],
"chartScrollbar": {},
"chartCursor": {
"cursorPosition": "mouse"
},
"categoryField": "date",
"categoryAxis": {
"parseDates": true,
"axisColor": "#DADADA",
"minPeriod": "ss"
},
"export": {
"enabled": true,
"position": "bottom-right"
}
});
chart.addListener("dataUpdated", zoomChart);
zoomChart();
});
</script>
</head>
<body>
<!-- HTML -->
<div id="chartdiv"></div>
</body>
</html>Велкомеserghei писал(а):Я библиотеку воткнул в АМС , а вот привязать данные - уже полгода спрашиваю, сам не знаю как прикрутить. SteelSeries без проблем устанавливается на карточку. А вот дальше.... Не поделитесь кодом??
Код: Выделить всё
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<meta http-equiv="Pragma" content="no-cache">
<!-- Styles -->
<style>
#chartdiv {
width : 100%;
height : 500px;
}
</style>
<!-- Resources -->
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/themes/none.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<script>
//var csv is the CSV file with headers
function csvJSON(csv){
var lines=csv.split("\n");
var result = [];
for(var i=0;i<lines.length;i++){
var obj = [];
if (lines[i] == '') continue;
if (i == 0) continue;
var currentline=lines[i].split(",");
var val = [];
for(var j=0;j<currentline.length;j++){
if (j == 0) {
var myDate = new Date(currentline[j]);
} else {
val.push(Number(currentline[j]));
}
}
result.push({
date: myDate,
x1: val[0],
x2: val[1],
x3: val[2],
x4: val[3],
x5: val[4],
x6: val[5]
});
}
return result; //JavaScript object
}
function zoomChart(){
chart.zoomToIndexes(chart.dataProvider.length - 20, chart.dataProvider.length - 1);
}
jQuery.get('gotdata.css', function(data) {
data = csvJSON(data);
console.log(data);
chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "none",
"legend": {
"useGraphSettings": true
},
"dataProvider": data,
"synchronizeGrid":true,
"valueAxes": [{
"id":"v1",
"axisColor": "#FF6600",
"axisThickness": 2,
"axisAlpha": 1,
"position": "left"
}, {
"id":"v2",
"axisColor": "#FCD202",
"axisThickness": 2,
"axisAlpha": 1,
"position": "right"
}, {
"id":"v3",
"axisColor": "#B0DE09",
"axisThickness": 2,
"gridAlpha": 0,
"offset": 50,
"axisAlpha": 1,
"position": "left"
}],
"graphs": [{
"valueAxis": "v1",
"type": "smoothedLine",
"lineColor": "#FF6600",
"lineThickness": 2,
"title": "Т На Улице",
"valueField": "x1",
"fillAlphas": 0
}, {
"valueAxis": "v1",
"lineColor": "#FCD202",
"type": "smoothedLine",
"lineThickness": 2,
"title": "Т До Испарителя",
"valueField": "x2",
"fillAlphas": 0
}, {
"valueAxis": "v1",
"lineColor": "#B0DE09",
"type": "smoothedLine",
"lineThickness": 2,
"title": "T После Испарителя",
"valueField": "x3",
"fillAlphas": 0
}, {
"valueAxis": "v1",
"type": "smoothedLine",
"lineThickness": 2,
"title": "Т До Конденцатора",
"valueField": "x4",
"fillAlphas": 0
}, {
"valueAxis": "v1",
"type": "smoothedLine",
"lineThickness": 2,
"title": "Т После Конденцатора",
"valueField": "x5",
"fillAlphas": 0
}, {
"valueAxis": "v1",
"type": "smoothedLine",
"lineThickness": 2,
"title": "% Открытия ЭРВ",
"valueField": "x6",
"fillAlphas": 0
}],
"chartScrollbar": {},
"chartCursor": {
"cursorPosition": "mouse"
},
"categoryField": "date",
"categoryAxis": {
"parseDates": true,
"axisColor": "#DADADA",
"minPeriod": "ss"
},
"export": {
"enabled": true,
"position": "bottom-right"
}
});
chart.addListener("dataUpdated", zoomChart);
zoomChart();
});
</script>
</head>
<body>
<!-- HTML -->
<div id="chartdiv"></div>
</body>
</html>Код: Выделить всё
serial.js:6 Uncaught TypeError: Cannot read property 'length' of undefined
at b.getClosestIndex (serial.js:6)
at Object.xToIndex (serial.js:11)
at b.handleCursorMove (serial.js:7)
at Object.a.inherits.b.fire (amcharts.js:1)
at Object.dispatchMovedEvent (amcharts.js:28)
at Object.handleMouseDown (amcharts.js:27)
at b.handleMouseDown (serial.js:1)
at HTMLDivElement.<anonymous> (amcharts.js:21)
Код: Выделить всё
Date ,TOut,TdoIspar,TpoIspar,TdoKonden,TpoKonden,ERVPos%
2017-4-23 0:15:3 ,0.00,0.00,0.00
2017-4-23 0:15:34 ,37.88,26.81,0.00
2017-4-23 0:16:3 ,37.88,26.81,0.00
2017-4-23 0:16:34 ,37.88,26.81,0.00
2017-4-23 0:17:3 ,37.88,26.81,0.00
2017-4-23 0:17:34 ,37.88,26.87,0.00
2017-4-23 0:18:3 ,37.88,26.87,0.00
2017-4-23 0:18:34 ,37.88,26.87,0.00
2017-4-23 0:19:10 ,37.88,26.87,0.00
2017-4-23 0:19:38 ,37.88,26.87,0.00
2017-4-23 0:20:8 ,37.88,26.87,0.00
2017-4-23 0:20:41 ,37.88,26.87,0.00
2017-4-23 0:21:8 ,37.88,26.87,0.00
2017-4-23 0:21:39 ,37.88,26.94,0.00
2017-4-23 0:22:8 ,37.88,26.94,0.00
Код: Выделить всё
<style>
.concept2 {
color: #333;
background: #BCC7B7 url(//%!/concept2.jpg) no-repeat;
background-size: 100% 100%;
}
#chartdiv {
width : 100%;
height : 500px;
}
</style>
------------
<body class="concept2">
<!-- HTML -->
<div id="chartdiv"></div>
</body>