Has anyone ever tried to create a Gannt like chart with QWT ?
See also this thread: http://www.qtcentre.org/threads/3175...tt-Chart-in-Qt
Has anyone ever tried to create a Gannt like chart with QWT ?
See also this thread: http://www.qtcentre.org/threads/3175...tt-Chart-in-Qt
A QwtPlotIntervalCurve with a symbol in QwtIntervalSymbol::Box style should be pretty close to the screenshot of your linked thread. But I guess you want to display more than the interval bars only.
Uwe
Hi Uwe,
Thanks for your reply.
I will give your idea a try.
The bars are fine. If i can show some 'name' of the tasks that was running on the Y-axis that would be great.
The input of my chart would be (still guessing, dont have anythng yet):
<task>
<id>waiting for trigger</id>
<starttime> 123123123123 </starttime>
<stoptime> 123123123223 </stoptime>
</task>
I can browse the file, and collect all events of the same id, and display them on the same curve, if i can then display the "waiting for trigger" on the y asis label, were good.
Thanks, sorry for the extra info.
Hi Uwe,
I've tried to follow your lead:
QVector<QwtIntervalSample> samples;
samples.append( QwtIntervalSample( 10, 8, 12 ) );
samples.append( QwtIntervalSample( 2, 3, 7 ) );
samples.append( QwtIntervalSample( 18, 17, 20 ) );
QwtIntervalSymbol symbol( QwtIntervalSymbol::Box );
QwtPlot *myPlot = new QwtPlot( NULL );
QwtPlotIntervalCurve *curve1 = new QwtPlotIntervalCurve("Curve 1");
curve1->setSymbol( &symbol );
curve1->setSamples( samples );
curve1->attach( myPlot );
curve1->setStyle( QwtPlotIntervalCurve::NoCurve );
for example : samples.append( QwtIntervalSample( 10, 8, 12 ) );
draws a box on X position 10, ranging from Y value 8 to 12. (e.g. a vertical box).
The interval is defined as [y1-y2]=f(x).
Any way to swap the x and y axis ?
Better idea ?
Thanks for any help.
Qt Code:
curve1->setOrientation( Qt::Horizontal );To copy to clipboard, switch view to plain text mode
Uwe
Thanks, got it up and running !
Uwe, you're the best !
Uwe,
Couple more questions...
1) i have created a TaskNamesDraw derived from QwtScaleDraw that draws the names on the y-axis, to get the same as in the other gannt thread. This is working as expected, except that only major ticks are drawn. For example if Yvalues range from 0 to 10, then only 0, 2, 4 etc. are drawn, but not the 1, 3, etc. How can i make it draw ALL labels ?
2) In stuff we talked about earlier we had the samples we provided to the plot defined as :
samples.append( QwtIntervalSample( 10, 8, 12 ) );
samples.append( QwtIntervalSample( 2, 3, 7 ) );
samples.append( QwtIntervalSample( 18, 17, 20 ) );
if i change this to :
samples.append( QwtIntervalSample( 10, 800000, 800100 ) );
samples.append( QwtIntervalSample( 2, 800400, 800500 ) );
samples.append( QwtIntervalSample( 18, 800600, 800700 ) );
i get 3 beautiful bars on the initial draw. If i zoom it it works perfectly;
When i zoom out (all the way to empty zoom stack), then the x-axis values are
somehow reset to 0...1000 and i loose my bars in the plot.
Is there some way to 'define' the overview x and y ranges ?
3) when zooming in, i only want x-axis zoom, not y-axis zoom.
How can i enforce this ?
Hope you can point me in the right directions that would be great.
No all ticks are painted, but maybe you didn't define the ticks you are missing.This is working as expected, except that only major ticks are drawn.
This is a question you find many, many times answered in this forum:i get 3 beautiful bars on the initial draw. If i zoom it it works perfectly;
When i zoom out (all the way to empty zoom stack), then the x-axis values are
somehow reset to 0...1000 and i loose my bars in the plot.
The zoomer is initialized with the current state of the scales and 0.0->1000.0 is the default setting. Obviously you are changing the scales later and forgot to reinitialize the zoomer: See http://qwt.sourceforge.net/class_qwt...58c52f0b5c7bc2
If you need one y axis only you can simply assign the other one to the zoomer: http://qwt.sourceforge.net/class_qwt...133a5cb6652e3dwhen zooming in, i only want x-axis zoom, not y-axis zoom.
How can i enforce this ?
If not you have to reimplement QwtPlotZoomer::zoom( const QRectF & ), where you adjust the y coordinates and then call the base class.
Uwe
With the first question, i meant that the derived virtual QwtText label(double v) const of the special QwtScaleDraw is only called for values 0, 2, 4 etc. but not for 1, 3, etc. What do you mean by "but maybe you didn't define the ticks you are missing" ?
When you are talking about the tick labels - not the ticks: yes, the labels are for major ticks only.
Uwe
ok, thanks.
Got the fixed y-axis zoom, independent of the x-axis zoom working, indeed by reimplementing the QwtPlotZoomer::zoom.
Also got the init of the zoomBase working.
The first problem is still giving me problems.
When i do : setAxisScale( QwtPlot::yLeft, 0, max, 1 ); and have the max set to the number of horizontal gannt lines it works.
But after a zoom in and out, they are gone again, and i end up with the labels on the major ticks.
How can i fix this ? connect the zoomed signal to a slot in the plot and call setAxisScale( QwtPlot::yLeft, 0, max, 1 ); again ?
In the end QwtPlotZoomer is a class that manipulates the scales using the same setAxisScale method you do in your application. That's why your scale is gone.
I recommend to overload QwtPlotZoomer::rescale to have complete control over the scale ticks. Simply copy the default implementation into your derived zoomer class, replace the internal stuff by using public getters and adjust the code to your needs.
Uwe
Last edited by thejester; 20th April 2011 at 12:29.
Hi Uwe,
Any idea on the dissapearing boxes ?
Thanks for all help !
Does QWT support a measurement tool ?
For instance if you press a mouse button at some location, move cursor somewhere else, it would be usefull to have an indication of the delta X and delta Y the user moved the mouse..
Hi thejester
would you like to share your code with gantt charts that you implemented?
It could help us to understand in which code are you working on.
thanks
Thanks uwe, will look into that one. Does that support measuring distances between any two points in plot ? or can it be modified to do that ?
Another question.
We want to optimise the number of horizontal lines on the Gannt chart.
Each curve in our plot has a fixed y value. This Y value is simply an integer. It would be nice (at least for our implementation) if the distance between for instance 2.0 and 3.0 could be set to the height of the text label.
Is that somehow possible ?
It controls and propagates the selection of points on the plot canvas and supports the selection with some sort of visual feedback. It is very configurable, what makes it sometimes hard to understand.
The layout system works the other way round: the size for the plot is given and the rest is calculated from it. So what you need to do is to implement a sizeHint for your plot widget, that somehow calculates its height from the font metrics of your text labels, so that the plot gets the size you want to have.We want to optimise the number of horizontal lines on the Gannt chart.
Each curve in our plot has a fixed y value. This Y value is simply an integer. It would be nice (at least for our implementation) if the distance between for instance 2.0 and 3.0 could be set to the height of the text label.
Another option is of course to adjust your y axis scales according to the current height of the plot canvas. For this you have to install an event filter for the plot canvas and catch the resize events. But be careful with such an implementation because changing the scales might trigger additional resize events und you might run into recursions or ping-pong situations ( QwtPlotRescaler does something similar ).
Hm ... have a look at QwtPlotRescaler::Expanding and check the navigation example to see how it works. This might be a solution if you decide to adjust the scales of your y axis.
Uwe
Hi Uwe, thanks for the quick response!
For the distance measuring, I have started a separate thread since more people can find it and since it has nothing to do with Gannt.
See http://www.qtcentre.org/threads/4128...suring-in-plot.
The other problem seems more difficult then expected. Have to think about that some more.
Bookmarks