#include "qwt_plot.h"
#include "qwt_scale_widget.h"
#include <QTimer>
#include <stdlib.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_grid.h>
#include <QTime>
PlottingGraph
::PlottingGraph(QWidget *parent
) , m_curve(0)
, m_time(0)
{
setupUi(this);
connect(drawButton, SIGNAL(clicked()), this, SLOT(draw()));
connect(timer, SIGNAL(timeout()), this, SLOT(draw()));
timer->start(300);
for (int i = 0; i < 100; i++)
{
m_x[i] = i;
m_y[i] = 0.0;
}
myPlot->setTitle("Temperature Channel");
myPlot
->setAxisTitle
(QwtPlot::xBottom,
"System Uptime [h:m:s]");
myPlot
->setAxisScaleDraw
(QwtPlot::xBottom,
new TimeScaleDraw(cpuStat.upTime()));
myPlot
->setAxisScale
(QwtPlot::xBottom,
0, HISTORY
);
myPlot
->setAxisTitle
(QwtPlot::yLeft,
"Values");
myPlot
->setAxisScale
(QwtPlot::yLeft,
-10000,
10000);
myPlot->setAutoReplot(true);
}
void PlottingGraph::on_drawButton_clicked()
{
}
void PlottingGraph::draw()
{
m_time++;
memmove(m_y, &m_y[1], 99 * sizeof(double));
m_y[99] = 1000 * sin((double)m_time / 360 * 3.1415 * 100) + rand() % 4000 - 2000;
for (int i = 0; i < 100; i++)
m_x[i]++;
if (!m_curve)
{
m_curve
->setPen
(QPen(Qt
::red));
m_curve->setData(m_x, m_y, 100);
gridy->attach(myPlot);
m_curve->attach(myPlot);
}
m_curve->setData(m_x, m_y, 100);
myPlot
->setAxisScale
(QwtPlot::xBottom, timeData
[HISTORY
- 1], timeData
[0]);
//m_time, m_time + 100); // auto replots myPlot
->setAxisScale
(QwtPlot::xBottom,
time.
("h:m:s"));
}
{
for ( int i = dataCount; i > 0; i-- )
{
for ( int c = 0; c < NCpuData; c++ )
{
if ( i < HISTORY )
data[c].data[i] = data[c].data[i-1];
}
}
cpuStat.statistic(data[User].data[0], data[System].data[0]);
data[Total].data[0] = data[User].data[0] +
data[System].data[0];
data[Idle].data[0] = 100.0 - data[Total].data[0];
if ( dataCount < HISTORY )
dataCount++;
for ( int j = 0; j < HISTORY; j++ )
timeData[j]++;
timeData[HISTORY - 1], timeData[0]);
for ( int c = 0; c < NCpuData; c++ )
{
data[c].curve->setRawData(
timeData, data[c].data, dataCount);
}
replot();
}
#include "qwt_plot.h"
#include "qwt_scale_widget.h"
#include <QTimer>
#include <stdlib.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_grid.h>
#include <QTime>
PlottingGraph::PlottingGraph(QWidget *parent)
: QDialog(parent)
, m_curve(0)
, m_time(0)
{
setupUi(this);
connect(drawButton, SIGNAL(clicked()), this, SLOT(draw()));
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(draw()));
timer->start(300);
for (int i = 0; i < 100; i++)
{
m_x[i] = i;
m_y[i] = 0.0;
}
myPlot->setTitle("Temperature Channel");
myPlot->setAxisTitle(QwtPlot::xBottom, "System Uptime [h:m:s]");
myPlot->setAxisScaleDraw(QwtPlot::xBottom,
new TimeScaleDraw(cpuStat.upTime()));
myPlot->setAxisScale(QwtPlot::xBottom, 0, HISTORY);
myPlot->setAxisTitle(QwtPlot::yLeft, "Values");
myPlot->setAxisScale(QwtPlot::yLeft, -10000, 10000);
myPlot->setAutoReplot(true);
}
void PlottingGraph::on_drawButton_clicked()
{
}
void PlottingGraph::draw()
{
m_time++;
memmove(m_y, &m_y[1], 99 * sizeof(double));
m_y[99] = 1000 * sin((double)m_time / 360 * 3.1415 * 100) + rand() % 4000 - 2000;
for (int i = 0; i < 100; i++)
m_x[i]++;
if (!m_curve)
{
m_curve = new QwtPlotCurve();
m_curve->setPen(QPen(Qt::red));
m_curve->setData(m_x, m_y, 100);
QwtPlotGrid *gridy = new QwtPlotGrid();
gridy->attach(myPlot);
m_curve->attach(myPlot);
}
m_curve->setData(m_x, m_y, 100);
myPlot->setAxisScale(QwtPlot::xBottom, timeData[HISTORY - 1], timeData[0]); //m_time, m_time + 100); // auto replots
QTime time = QTime::currentTime();
myPlot->setAxisScale(QwtPlot::xBottom, time.("h:m:s"));
}
void PlottingGraph::timerEvent(QTimerEvent *)
{
for ( int i = dataCount; i > 0; i-- )
{
for ( int c = 0; c < NCpuData; c++ )
{
if ( i < HISTORY )
data[c].data[i] = data[c].data[i-1];
}
}
cpuStat.statistic(data[User].data[0], data[System].data[0]);
data[Total].data[0] = data[User].data[0] +
data[System].data[0];
data[Idle].data[0] = 100.0 - data[Total].data[0];
if ( dataCount < HISTORY )
dataCount++;
for ( int j = 0; j < HISTORY; j++ )
timeData[j]++;
setAxisScale(QwtPlot::xBottom,
timeData[HISTORY - 1], timeData[0]);
for ( int c = 0; c < NCpuData; c++ )
{
data[c].curve->setRawData(
timeData, data[c].data, dataCount);
}
replot();
}
To copy to clipboard, switch view to plain text mode
Bookmarks