c++ - QCustomPlot: How to set percent on the y-axis? How to change tick label alignment? -


i playing around qcustomplot libary qt. created plots succesfully. got still questions:

1: how can set y-axis range 0% 100%?

2: tick labels centered below ticks. how can change left alignment?

thanks help.

peter

// generate data:     qvector<double> x(101), y(101); // initialize entries 0..100     (int i=0; i<101; ++i)     {       x[i] = (i*960); // x goes -1 1       y[i] = x[i]/96000.0; // let's plot quadratic function     }     // create graph , assign data it:     ui->customplot->addgraph();     ui->customplot->graph(0)->setdata(x, y);      // set axes ranges, see data:     ui->customplot->xaxis->setticklabeltype(qcpaxis::ltdatetime);     ui->customplot->xaxis->setdatetimespec(qt::utc);     ui->customplot->xaxis->setdatetimeformat("hh:mm");     ui->customplot->xaxis->setautotickstep(false);     ui->customplot->xaxis->settickstep(3600);     ui->customplot->xaxis->setrange(0, 86399);     ui->customplot->yaxis->setrange(0, 1);     ui->customplot->replot();  ui->customplot->xaxis->setbasepen(qpen(qt::white, 1)); ui->customplot->yaxis->setbasepen(qpen(qt::white, 1)); ui->customplot->xaxis->settickpen(qpen(qt::white, 1)); ui->customplot->yaxis->settickpen(qpen(qt::white, 1)); ui->customplot->xaxis->setsubtickpen(qpen(qt::white, 1)); ui->customplot->yaxis->setsubtickpen(qpen(qt::white, 1)); ui->customplot->xaxis->setticklabelcolor(qt::white); ui->customplot->yaxis->setticklabelcolor(qt::white); ui->customplot->xaxis->grid()->setpen(qpen(qcolor(140, 140, 140), 1, qt::dotline)); ui->customplot->yaxis->grid()->setpen(qpen(qcolor(140, 140, 140), 1, qt::dotline)); ui->customplot->xaxis->grid()->setsubgridpen(qpen(qcolor(80, 80, 80), 1, qt::dotline)); ui->customplot->yaxis->grid()->setsubgridpen(qpen(qcolor(80, 80, 80), 1, qt::dotline)); ui->customplot->xaxis->grid()->setsubgridvisible(true); ui->customplot->yaxis->grid()->setsubgridvisible(true); ui->customplot->xaxis->grid()->setzerolinepen(qt::nopen); ui->customplot->yaxis->grid()->setzerolinepen(qt::nopen); ui->customplot->xaxis->setupperending(qcplineending::esspikearrow); ui->customplot->yaxis->setupperending(qcplineending::esspikearrow); 

you should solve both questions with

ui->customplot->yaxis->setrange(0, 100, qt::alignleft); 

edit: show custom text ticks, should add code:

qvector<double> tickvalues; qvector<qstring> ticklabels; // can safely change values according output tickvalues << 0  << 20 << 40 << 60 << 80 << 100; ticklabels << "0" << "20%" << "40%" << "60%" << "80%" << "100%"; // disable default ticks , labels ui->customplot->yaxis->setautoticks(false); ui->customplot->yaxis->setautoticklabels(false); // add custom values , labels ui->customplot->yaxis->settickvector(ticksvalues); ui->customplot->yaxis->settickvectorlabels(ticklabels); 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -