I have a function that plots multiple graphs overlapped taking a period of time (like 2 months) and dividing that period by x days. Because the number of days in that period is not necessarily divisible by x, most times chance is that the last graph will be shorter in days than all the others. When I click on the graph I am able to see the value on each graph at that key where I clicked at. The problem is that if I click on a key beyond the last key of the last graph(which is the shorther one) I dont have to take the value on the last graph because there is none at that point. If I use mouseevent->pos.x to compare to the last key in the last graph it works perfectly but if I use tracer->position->key() the tracer gets stuck at the final key of the last graph. Why the second option doesnt work?

double xCoord = plot->xAxis->pixelToCoord(event->pos().x()); tracer->setGraphKey(xCoord); int days = tracer->position->key() / 86400; int timeSecs = int(tracer->position->key()) % 86400; QString time = QTime(QTime::fromMSecsSinceStartOfDay(timeSecs*1000)).toString(); double temperature[plot->graphCount()]; QString message; int lastgraph = plot->graphCount()-1; int lastIndex = plot->graph(lastgraph)->dataCount()-1; double lastDate = plot->graph(lastgraph)->data()->at(lastIndex)->key; int graphs; if ( xCoord > lastDate ) // if i use tracer->position->key() > lastDate, the tracer gets stuck to the last key on the last graph if I try to click at any point beyond that; the last graph is shorter in days than the others graphs = plot->graphCount()-1; else graphs = plot->graphCount(); for (int i = 0; i < graphs; ++i) { tracer->setGraph(plot->graph(i)); temperature[i] = tracer->position->value(); message.append(QString("day %1 %2 temperature %3 \t %4 \n").arg(days).arg(time).arg(temperature[i]).arg(plot->graph(i)->name())); } ui->label->setText(message);

Please ask me to reformulate if you didnt understand something.