PDA

View Full Version : Qwt and custom axis



jiveaxe
14th November 2007, 12:23
I would like to add to my project a statistics section, with charts, ecc. Searching in the forum I found links to wysota's charts (http://www.wysota.eu.org/charts.html), and Qwt (http://qwt.sourceforge.net/). Since wysota's project implements only barchart I have downloaded qwt; it is very complete and powerful. I have made a simple application just to try it and learn the basics.

My problem is this: my application should read data from a magazine database and get for each issue the number of a certain type of article (for example, reviews): so, Gen 07 - 5 reviews, Feb 07 - 3 reviews, Mar 07 - 5 reviews, etc, and build a line chart. Get the data is not the problem; it is have on x-axis the sequence of issues (Gen 07, Feb 07, Mar 07, ecc) instead of a numerical progression.

Thanks

Uwe
14th November 2007, 13:11
Please stop crossposting.

Uwe

jiveaxe
14th November 2007, 13:20
Crossposting? Where?

jiveaxe
14th November 2007, 16:50
I reply myself (some time happens); looking one of the example in the documentation I have found a simple solution; I have made this new class:


class MonthsScaleDraw: public QwtScaleDraw
{
public:
MonthsScaleDraw()
{
}
virtual QwtText label(double v) const
{
switch(int(v))
{
case 1:
return QString("Jan '07");
break;
case 2:
return QString("Feb '07");
break;
case 3:
return QString("Mar '07");
break;
case 4:
return QString("Apr '07");
break;
case 5:
return QString("May '07");
break;
case 6:
return QString("Jun '07");
break;
case 7:
return QString("Jul '07");
break;
case 8:
return QString("Aug '07");
break;
case 9:
return QString("Sep '07");
break;
case 10:
return QString("Oct '07");
break;
case 11:
return QString("Nov '07");
break;
case 12:
return QString("Dec '07");
}
}
};

then in my derivate of QwtPlot


...
setAxisTitle(QwtPlot::xBottom, "Issues");
setAxisScaleDraw(QwtPlot::xBottom, new MonthsScaleDraw());
setAxisScale(QwtPlot::xBottom, 1, 12);
...

Let me now if there is a better solution.

Regards