PDA

View Full Version : How to adapt the x-axis with strings instead of with numbers ?



Agfels
6th August 2010, 16:06
Hello Friends,

I am not new by Qt, however I am using the first time the Qwt library for my Purposes. Well, My Questions are following:
a-) How can I get the x-axis of my Histogram scaled with strings instead with numbers ?
b-) what does mean "intervals" and "values" in the following code. I understood it as "intervals" means the distance between each two beam (y-axis) and "value" means the value of this beam (x-axis) !

QwtArray<QwtDoubleInterval> intervals(numValues);
QwtArray<double> values(numValues);

double pos = 0.0;
for ( int t = 0; t < (int)intervals.size(); t++ )
{
const int width = 5 + rand() % 5; //15;
const int value = rand() % 100;

intervals[t] = QwtDoubleInterval(pos, pos + double(width));
values[t] = 120; //value;

pos += width;
}

c-) I just have to make a histogram for exactly 7 parameters (x-axis) looking like this:

the x-axis MUST like this:

|------------|------------|-------------|------------|------------|-----------|
ABB BCC CDD DEE EFF GFF PPP

Question: How can I can determine the width of each beam that I have use in order to calculate the "interval" ? I have tried all Qwt-Examples, but I do not understand the Calculation's philosophy behind that, so I can not move on. Please I need your help.
Thanks.

Uwe
8th August 2010, 19:54
class YourScaleDraw: public QwtScaleDraw
{
...
virtual QwtText label( double value) const
{
if ( value == 0.0 )
return "ABB";
if ( value == 1.0 )
return "BCC";
...

return QwtScaleDraw::label(value);

};

plot->setAxisScale(QwtPlot::xBottom, 0.0, 6.0, 1.0);
plot->setAxisMaxMinor(QwtPlot::xBottom, 0);
plot->setAxisScaleDraw(QwtPlot::xBottom, new YourScaleDraw());

Uwe

Agfels
17th August 2010, 13:36
Hi Uwe,

Many thanks for the Help, but I am still having problems to get it done. Here is a bit part of the source code:

class ModulationScaleDraw: public QwtScaleDraw
{
public:
ModulationScaleDraw()
{
}
virtual QwtText label(double v) const
{
switch (int(v))
{ case 1: return QString("FM"); break;
case 2: return QString("AM"); break;
case 3: return QString("PM"); break;
case 4: return QString("FA"); break;
case 5: return QString("PA"); break;
case 6: return QString("konst."); break;
case 7: return QString("unbekannt");break;
}
}

private:
QStringList modlabel;
};


Main.cpp:


{
int pos = 0;
const double width = 1.98;
// Klassenbreite: = (x-max - x-min) / (2n)*1/3
// (M_TYPE * ((dMaxX-dMinX) - dMinX))/ (dMaxX -dMinX);
// (dMaxX-dMinX)/(M_TYPE);
// (M_TYPE * ((dMaxX-dMinX) - dMinX))/ (dMaxX -dMinX);

for (int iInterval = 0; iInterval < M_TYPE; iInterval++ )
{
intervals[iInterval] = QwtDoubleInterval(pos, pos + double(width));
switch (iInterval)
{ case M_F : values [0] += fm_value; break;
case M_P : values [1] += am_value; break;
case M_A : values [2] += pm_value; break;
case M_F_A : values [3] += fa_value; break;
case M_P_A : values [4] += pa_value; break;
case M_KEINE : values [5] += c_value; break;
}

pos += width;
}

histo->setData(QwtIntervalData(intervals,values));
histo->attach(plotDiag);

plot->setAxisTitle(QwtPlot::yLeft, " Anzahl ");
plot->setAxisScale(QwtPlot::yLeft, 0.0, iP);

//The system crashed here with following lines. TODO: Find the reasons ????

plotDiag->setAxisScaleDraw(QwtPlot::xBottom, new ModulationScaleDraw());
plotDiag->setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
plotDiag->setAxisScale(QwtPlot::xBottom, 1.0, M_TYPE, 1.0);
plotDiag->setAxisMaxMinor(QwtPlot::xBottom, 0);
}

FelixB
10th June 2011, 07:57
does anyone know why this thread gets pushed? I don't see any new posting (except mine ;) )

Uwe
5th August 2011, 15:38
Probably someone has voted - for whatever this poll was good for,

Uwe

wysota
12th August 2011, 22:55
I've closed the poll. It didn't make much sense anyway. If someone wants it reopened and has a good argument for doing so, let me know.