## View Poll Results: Qwt: Scaling the x-Axis with strings how to do it ?

Voters
7. You may not vote on this poll
• Qwt

7 100.00%
• Qt

1 14.29%
Multiple Choice Poll.

1. Beginner
Join Date
Aug 2010
Posts
7
Qt products
Platforms

## How to adapt the x-axis with strings instead of with numbers ?

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.

2. Uwe
Expert
Join Date
Feb 2006
Location
Munich, Germany
Posts
3,241
Thanked 860 Times in 809 Posts
Qt products
Platforms

## Re: How to adapt the x-axis with strings instead of with numbers ?

Qt Code:
`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());`
To copy to clipboard, switch view to plain text mode

Uwe

3. Beginner
Join Date
Aug 2010
Posts
7
Qt products
Platforms

## Re: How to adapt the x-axis with strings instead of with numbers ?

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);
}

Join Date
Oct 2010
Location
Berlin, Germany
Posts
358
Thanks
18
Thanked 68 Times in 66 Posts
Qt products
Platforms

## Re: How to adapt the x-axis with strings instead of with numbers ?

does anyone know why this thread gets pushed? I don't see any new posting (except mine )

5. Uwe
Expert
Join Date
Feb 2006
Location
Munich, Germany
Posts
3,241
Thanked 860 Times in 809 Posts
Qt products
Platforms

## Re: How to adapt the x-axis with strings instead of with numbers ?

Probably someone has voted - for whatever this poll was good for,

Uwe

6. ## Re: How to adapt the x-axis with strings instead of with numbers ?

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.