PDA

View Full Version : How to make the x-Bottom scale fixed.



Tavit
4th June 2008, 15:20
Hi friends i have a problem with my Plotting program. I have a db in which i save the data i have acquired. Initially the db is empty with no values. I need to have a fixed time scale from 0 to 60 seconds. Now once i click the start acquisition button i have to start acquiring data from a external device and save it to the DB and plot it. Its real time plotting. so i have to plot as i acquire the data. But the x-bottom scale changes according to the amount of data present in the db.
example - If i have only 4 values acquired to the DB the scale is changed to [0 to 3]. It looks like the image i have attached named (3).

If have say 40 values are added to the db the scale is changed to 35. It looks like the image i have attached named (35)

I actually wanted the scale to stay fixed to 60 and the graph to grow from the initial value as the data keeps adding in the graph has to grow gradually.Some thing like the snapshot (60) i have attached.

what do i need to do so that the x-bottom scale is fixed and the data to be plotted with out changing the scale irrespective of the amount of data present in the DB like in the image named (60).


Thank You
Please looking forward for a reply.

Tavit
5th June 2008, 06:24
Hi friends how do i fix the the x-bottom size of a qwt plot widget.


myPlot->setTitle("Data Acquisition");
myPlot->setAxisTitle(QwtPlot::xBottom, "System time");
myPlot->setAxisScale(QwtPlot::xBottom, 0, 60);
myPlot->setAxisTitle(QwtPlot::yLeft, "Bar");
myPlot->setAxisScale(QwtPlot::yLeft, 0, 100);
myPlot->setAutoReplot(true);


I am using the above code to set the x-bottom scale from 0 to 60. But when i click the start plotting button the bottom scale is changed according to the number of values present in the db. I wanted the scale to stay at 0 to 60 only and the graph to plot according to the number of values present in the db.I am able to retrive data from the db every second but my only problem is the scale which changes i want it to be fixed. How can i do that. ??


Thank You

Uwe
5th June 2008, 06:39
The code above is already what you need to do. Obviously someone else is also changing the scale or re-enables autoscaling.

Uwe

Tavit
5th June 2008, 06:59
Hi uwe problem solved. Thank You for the reply.

In my plot function i had this


curve->setPen(QPen(Qt::red));
//myPlot->setAxisScale(QwtPlot::xBottom, m_vx[0], m_vx[m_vx.count() - 1]);


Just commented the second line and Bingo. !! But once the graph reaches the x-bottom point 60. I wanted the graph to be cleared and the next graph which again starts with 0 to be started fresh again. I have the data in the db in this format ..


TIME DATA
0 21
1 24
2 28
3 20
. .
. .
. .
60 24
0 22
1 31
2 26
3 23
4 19
. .
. .
. .
60 27

Time keeps repeating from 0 to 60 so once the graph is plotted from 0 to 60 it has to be cleared and the graph has to start again from next 0 to 60 and so on. I am not able to figure out how to clear the graph which is displayed on the screen once it reaches 60.Because of this once the graph reaches 60 weird things happen. How should i clear the graph from the screen uwe. ?

Thank You

Tavit
5th June 2008, 11:16
Hi uwe i used the clear slot to clear the plot on a button clicked.


void graphplotting::on_pushButton_clicked()
{
myPlot->clear();
}


But i get a exception error. I tried so much but i still get the same error.
where am i going wrong uwe. !!!


Thank You

jacek
5th June 2008, 22:48
Such error appears when you try to access unallocated memory.

When you invoke QwtPlot::clear() it deletes all attached curves, so this error might appear if you access "curve" after push button has been clicked.

Tavit
6th June 2008, 04:55
Hi jacek I have looked so much for an example which shows how to clear plots. But cud't find any. I have been tryin since yeste with this problem but cud't slove it. Pls tell me what i have to do to clear this error.



Thank You

Tavit
6th June 2008, 13:08
Hi some one pls give me an example to clear( ) a plot . I don't find any on the net. !!! :(


Thank You

Tavit
7th June 2008, 16:06
Hi every one,

I tried so much , I tried the qwt example realtime_plot example in which there is a clear function . Into my program but still i get a exception. Some one pls help me i am really stuck at this place past 2 dazz. !! Tried all the things i cud.But no o/p .:crying: Give me a example or tell me how to use the qwtPlot->clear(); in the program.


Thank You

jacek
8th June 2008, 15:19
Where do you use "curve" varaible?

Tavit
8th June 2008, 18:36
Hello jacek Thankx for the reply, I solved my problem . :)


void RS232_Receive::retrive()
{
{
m_curve = new QwtPlotCurve("myPlot");
myPlot->clear();
myPlot->replot();
//draw();
}
draw();
}
}

I did this but once i clear the curve i wanted to call the draw function so that the next values is plotted from start after the present graph is cleared from the screen. But i am not getting it, the new curve is not plotted. !! Where am i going wrong .

Thank You jacek

jacek
9th June 2008, 01:10
myPlot->clear() deletes the existing curve, so you have to create a new one and attach it to the plot.

Alternatively you can simply remove all the data from the curve and invole myPlot->replot() instead of myPlot->clear().

Tavit
12th June 2008, 13:13
Hi friends i solved my Clear problem. I am able to clear the curve but now once the curve is cleared the next curve is not plotted. The screen stays blank. I am clearing the curve once the count of 60 is completed. And wanted the next curve to sart plotting but there seems to be a problem after the curve is cleared the next new curve is not plotting.



void graphplot::retrive()
{
int a=(rand()%10)+10;
QString j(QString::number(a));
if (count<60)
{
QSqlQuery m_query;
QString sq1("select max(s_x)+1 from newtest_table");
m_query.exec(sq1);
QString sq("INSERT INTO newtest_table values(%1,%2)");
sq = sq.arg(count)
.arg(j);
m_query.exec(sq);
count++;
textBrowser->append(j);
textBrowser->ensureCursorVisible();

}
else
{
count=0;
retrive();

myPlot->clear();// I am trying to clear and go to the next value of the plot and start the graph plot from 0 again here.
myPlot->replot();
m_curve = 0;
m_curve = new QwtPlotCurve("myCurve");
m_curve->attach(myPlot);
draw(); // I am trying to call the draw so that the next curve is plotted.But the new curve does not plot.
}
}
void graphplot::draw()
{
QSqlQuery q("SELECT s_x, s_y FROM newtable ");
m_vx.clear();
m_vy.clear();
if(q.exec())
{
if (q.first())
{
do
{
m_vx.push_back(q.value(0).toDouble());
m_vy.push_back(q.value(1).toDouble());
} while(q.next());
}
if (m_vx.count() <= 0) // no data no curve.
return;
m_lastTime = (int)m_vx[m_vx.count() - 1];
if (! m_curve)
{
m_curve = new QwtPlotCurve();
m_curve->attach(myPlot);
}
m_curve->setPen(QPen(Qt::red));
m_curve->setData(m_vx.data(), m_vy.data(), m_vx.count());
myPlot->replot();
qDebug("m_timer->start(999)");
m_timer->start(999);
}
}


pls tell me where i am going wrong.


Thank You

Tavit
12th June 2008, 14:23
Hi jacek i even tried what you asked me to myPlot->replot(), But this does't seem to work there is no change in the curve it just plots till 60 and stays there it does't clear or replot.When i use myPlot->clear it plots till 60 and clears there but the next curve is not plotted.The qwt plot widget stays blank.
Pls tell me what is the mistake i am doing. jacek


Thank you