How can i remove qchart unuseful area?
-
Hi,
I am beginner in Qt. Firstly, I want to build a line chart which starts from first pixel of QFrame , end last pixel of QFrame. I attached a picture. In this picture, how i can remove the area which is described with red arrows.Secondly, i want to add a axis for chart. the axis normally goes to 0,....,n(left to right). but i want to build an axis start right to left. i am using the negative point of the QLineSeries. Is it ok? Do you know any solution except mine?
Finally, in my x axis, i want to seperate a fixed value. In other words, the x axis is have 800 point in every time. If i add 2 point to series, it display 2 point on 800 point. If i add 500 point to series, it display 500 point on 800 point. It may be not clear, because of that i attached a picture. I am send the code which i am working on. Could you help me? Thank you :)
Code:
void MainWindow::lineChart(QFrame *horizontalFrame){
// set pen for series QPen pen(QRgb(0x00aa00)); pen.setWidth(2); //try some example datas QLineSeries *series = new QLineSeries(); series->setPen(pen); series->append(0,1); series->append(-1,4); //set x axis parameters QValueAxis* axisX = new QValueAxis(); axisX->setRange(-100,0); axisX->setLabelsVisible(false); axisX->setGridLineVisible(false); axisX->setLineVisible(false); axisX->setShadesVisible(false); axisX->setMinorGridLineVisible(false); //create chart with attributes QChart *chart = new QChart(); chart->addAxis(axisX,Qt::AlignBottom); series->attachAxis(axisX); chart->setBackgroundBrush(Qt::white); chart->layout()->setContentsMargins(0, 0, 0, 0); chart->setBackgroundRoundness(0); chart->setMaximumSize(810,100); chart->setMinimumSize(810,100); chart->setPreferredSize(810,100); chart->addSeries(series); chart->legend()->hide(); //create chartview with some attributes QChartView *chartview = new QChartView(chart); chartview->setRenderHint(QPainter::Antialiasing); chartview->setParent(horizontalFrame); chartview->setContentsMargins(0,0,0,0);
}
-
Take a look at QChart::margins()
-
@Christian-Ehrlicher Thank you :) How can split x axis to 800 fixed point? Do you know anything about this subject? Thank you again :)
-
QChart is a QGraphicsWidget so https://doc.qt.io/qt-5/qgraphicswidget.html#size-prop maybe?
-
@Christian-Ehrlicher Thank you for quick reply, i have tried but not working :( 2 data point completely envelop the chart like previously.
Thank you so much :)