In QwtMultiBarChart with 2 grouped series, how can one know if the cursor is on the first or the se
Brought to you by:
rathmann
|
From: Younes K. <kha...@gm...> - 2019-02-10 22:56:05
|
Hello,
I have a QwtMultiBarChart with 2 series. So I have two columns per point.
When the users puts the cursor on the chart, I am trying to figure out
whether it points to the first or the second column.
Till now, I was trying to do so with label position and I assumed that the
label is at the exact middle, i.e. between the two columns.
However, by printing the cursor and label position, and now know that it is
not, it seems to be in the middle of the second column.
Here is my code:
qreal current_label_position;
int histo_bound_idx=-1;
int titration_or_tendancy = 0; // 0 tiration, 1 tendancy
int ticks_size =
scaleDraw->scaleDiv().ticks(QwtScaleDiv::MinorTick).size();
//qDebug() << ticks_size;
qreal distance = scaleDraw->labelPosition(1).x() -
scaleDraw->labelPosition(0).x();
int i=0;
for (i=0; i < ticks_size; i++)
{
current_label_position = scaleDraw->labelPosition(i).x();
// First bar
if (i == 0 && (xPos < current_label_position) ){
histo_bound_idx = i;
titration_or_tendancy = 1;
break;
}
else if (i == ticks_size - 1 && (xPos > current_label_position)){
histo_bound_idx = i;
titration_or_tendancy = 0;
break;
}
else{
if (xPos < current_label_position
//&& xPos > (current_label_position -
((current_label_position - scaleDraw->labelPosition(i - 1).x())/2)) ){
&& xPos > current_label_position - (distance/2)
){
histo_bound_idx = i;
titration_or_tendancy = 1;
break;
}
else if (xPos > current_label_position
//&& xPos < (scaleDraw->labelPosition(i + 1).x()
- ((scaleDraw->labelPosition(i + 1).x() - current_label_position)/2))
&& xPos < current_label_position + (distance/2)
){
histo_bound_idx = i;
titration_or_tendancy = 0;
break;
}
}
}
Is there a better way to do this ?
If not, why the label is not printed between the two columns ?
Best regards,
Younes
P.S. Picture attached
--
Younes Khadraoui, PhD
*Co-Founder at Ostadhi.com | Research Engineer | Data Scientist |
Enterpreneur*
|