why extra lines appear here by QCharts
-
hello,i have used the QChats to draw one line,but when i finish,there are some extra line appeared,could you tell me why these lines here ,thank you so much
void createCharts() { QChart *fenshiChart = new QChart(); fenshiChart->setBackgroundBrush(QBrush(Qt::black)); fenshiChart->legend()->setVisible(false); fenshiChart->setMargins(QMargins(0,0,0,0)); fenshiChart->layout()->setContentsMargins(0,0,0,0); fenshiChart->setBackgroundRoundness(0); ui->fenshiLineChart->setChart(fenshiChart); ui->fenshiLineChart->setRenderHint(QPainter::Antialiasing); ui->fenshiLineChart->setContentsMargins(QMargins(0,0,0,0)); QLineSeries *series0 = new QLineSeries(); QPen pen; pen.setStyle(Qt::SolidLine); pen.setWidth(1); pen.setColor(Qt::white); series0->setPen(pen); fenshiChart->addSeries(series0); pen.setWidth(1); pen.setColor(QColor(176,0,0)); QValueAxis *axisX = new QValueAxis; axisX->setLabelsVisible(false); axisX->setRange(1,240); axisX->setTickCount(5); axisX->setLinePen(pen); axisX->setGridLinePen(pen); axisX->setMinorTickCount(1); axisX->setShadesVisible(false); QValueAxis *axisY = new QValueAxis; axisY->setTickCount(27); axisY->setLinePen(pen); axisY->setGridLinePen(pen); axisY->setLabelsColor(Qt::white); axisY->setLabelFormat("%.2f"); pen.setStyle(Qt::DotLine); axisX->setMinorGridLinePen(pen); fenshiChart->addAxis(axisX,Qt::AlignBottom); fenshiChart->addAxis(axisY,Qt::AlignLeft); series0->attachAxis(axisX); series0->attachAxis(axisY); }void addData() { //data int itemNumInt = itemNum; QLineSeries *series0 = (QLineSeries *)ui->fenshiLineChart->chart()->series().at(0); series0->clear(); qreal index = 0; for (int i=0;i<itemNumInt;i++) { if((time[i]>=93000 && time[i]<113000) || (time[i]>130000 && time[i]<=150000)) { index += 1; points.append(QPointF(index,QString::asprintf("%.2f",hstTodayClose[index-1]/100.00).toDouble())); } } series0->append(points); }


-
there could be junk data in the input. Add them one after another and you may be able to find out which ones are junk.
-
What if you exclude the number->QString formatting->number step when you are appending your points. Do you still get these artifacts?
-
@mchinand thank you ,i know that is not a good method to do so , but i need the required precision ,so have any other better method to take place? in the other hand, i have exclude that ,but there is still have the extra line on the graph , alas~~~
I think the preferred way to do that formatting (format to two decimal places) is:
QString::number(hstTodayClose[index-1]/100.00, 'f', 2).toDouble();There's nothing weird with your indexing of
time[]withiandhstTodayClose[]withindex? This depends on how those arrays are populated, so could be correct. -
I think the preferred way to do that formatting (format to two decimal places) is:
QString::number(hstTodayClose[index-1]/100.00, 'f', 2).toDouble();There's nothing weird with your indexing of
time[]withiandhstTodayClose[]withindex? This depends on how those arrays are populated, so could be correct.@mchinand ```
QString::number(hstTodayClose[index-1]/100.00, 'f', 2).toDouble();this method i have used, but it loss precision when i debug out the number. the points was initialized like this:``` QList<QPointF> points={};and i tried to add points.clear() ,but it seems like have no help on the grap ,the extra lines are still there.
-
@mchinand thank you ,i know that is not a good method to do so , but i need the required precision ,so have any other better method to take place? in the other hand, i have exclude that ,but there is still have the extra line on the graph , alas~~~
@mr-five
- Check @mchinand's comment: if
pointsis not empty (left over from before?) you would "jump back" tox == 0, could make it look screwy. - Verify how it looks using just all points as
QPointF(index, index)instead. Should be diagonal line. Any artefacts? - Verify the length of
hstTodayClose, is[index-1]always within bounds? - Binary chop the number of points you plot, do the artefacts still appear? Keep chopping in half.
- To pass a floating point number of 2 decimal places you shouldn't need to convert to a string and then back to a number. Something like
int(num * 100 + 0.5) / 100.0should work.
- Check @mchinand's comment: if
-
@mr-five
- Check @mchinand's comment: if
pointsis not empty (left over from before?) you would "jump back" tox == 0, could make it look screwy. - Verify how it looks using just all points as
QPointF(index, index)instead. Should be diagonal line. Any artefacts? - Verify the length of
hstTodayClose, is[index-1]always within bounds? - Binary chop the number of points you plot, do the artefacts still appear? Keep chopping in half.
- To pass a floating point number of 2 decimal places you shouldn't need to convert to a string and then back to a number. Something like
int(num * 100 + 0.5) / 100.0should work.
- Check @mchinand's comment: if
-
@mr-five
Looks like two separate diagonal lines. Does yourxvalue change from positive to negative?? What is the range of yourindexvariable? Make itint indexinstead ofqreal, any difference? Only print the first 50% of all the points, do you then get just the left-hand line? -
@mr-five
Looks like two separate diagonal lines. Does yourxvalue change from positive to negative?? What is the range of yourindexvariable? Make itint indexinstead ofqreal, any difference? Only print the first 50% of all the points, do you then get just the left-hand line?i found one probable cause is that i forgot to initialize the range of the Y axis, and after i do so:
ui->fenshiLineChart->chart()->axes(Qt::Vertical).at(0)->setRange(todayLow[itemNum-1],todayHigh[itemNum-1]);the graph only leave one extra line like this,and i do not know the reason again,thank you
-
i found one probable cause is that i forgot to initialize the range of the Y axis, and after i do so:
ui->fenshiLineChart->chart()->axes(Qt::Vertical).at(0)->setRange(todayLow[itemNum-1],todayHigh[itemNum-1]);the graph only leave one extra line like this,and i do not know the reason again,thank you


