TRying to create a graph :)

This commit is contained in:
samcake 2016-03-23 17:52:06 -07:00
parent 851cbb1c46
commit 6d6f0398f5

View file

@ -11,6 +11,7 @@
import QtQuick 2.5
import QtQuick.Controls 1.4
Column {
spacing: 8
Column {
@ -28,12 +29,44 @@ Column {
Label {
text: qsTr(modelData.split(":")[0])
}
property var value: stats.config[modelData.split(":")[1]]
property var value: stats.config[modelData.split(":")[1]]
property var valueHistory : new Array()
property var valueMax : 1000
property var tick : 0
Label {
text: value
horizontalAlignment: AlignRight
}
Canvas {
id: mycanvas
width: 100
height: 200
onPaint: {
tick++;
valueHistory.push(value)
if (valueHistory.length > 100) {
valueHistory.shift();
}
var ctx = getContext("2d");
if (tick % 2) {
ctx.fillStyle = Qt.rgba(0, 1, 0, 0.5);
} else {
ctx.fillStyle = Qt.rgba(0, 0, 0, 0.5);
}
ctx.fillRect(0, 0, width, height);
var widthStep= width / valueHistory.length;
ctx.lineWidth="5";
ctx.beginPath();
ctx.strokeStyle="green"; // Green path
ctx.moveTo(0,height);
for (var i = 0; i < valueHistory.length; i++) {
ctx.lineTo(i * widthStep, height * (1 - valueHistory[i] / valueMax) );
}
ctx.lineTo(width, height);
ctx.stroke(); // Draw it
}
}
}
}
}