From 6d6f0398f53fb442ced4a97f67b8544354889877 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 23 Mar 2016 17:52:06 -0700 Subject: [PATCH] TRying to create a graph :) --- examples/utilities/tools/render/stats.qml | 37 +++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/examples/utilities/tools/render/stats.qml b/examples/utilities/tools/render/stats.qml index bc70358c54..7140f81270 100644 --- a/examples/utilities/tools/render/stats.qml +++ b/examples/utilities/tools/render/stats.qml @@ -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 + } + } } } }