Margins in a bar chart Grid <QtCharts>
Solved
General and Desktop
-
Hello,
Im trying to draw through <QtCharts> the next bar chart:
http://img.fenixzone.net/i/po3YJnz.png
but im moment, I only get the next result:
http://img.fenixzone.net/i/THrm7Jp.pngI would like to have the grid margins in 0, as in the first figure.
Please, if somebody know how to adjust the Grid Margins to 0, would be so kind to help me?
Thanks in advance.
Here is my code
main.cpp
#include <QtWidgets/QApplication> #include <QtWidgets/QMainWindow> #include <QtCharts/QChartView> #include <QtCharts/QBarSeries> #include <QtCharts/QBarSet> #include <QtCharts/QLegend> #include <QtCharts/QBarCategoryAxis> #include <QtCharts/QHorizontalStackedBarSeries> #include <QCategoryAxis> QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { QApplication a(argc, argv); QBarSet *set0 = new QBarSet("1"); *set0 << 2; QHorizontalStackedBarSeries *series = new QHorizontalStackedBarSeries(); series->append(set0); QChart *chart = new QChart(); chart->addSeries(series); chart->setTitle("Jose Char"); chart->setAnimationOptions(QChart::SeriesAnimations); QStringList categories; categories << "MyBar"; QBarCategoryAxis *axis = new QBarCategoryAxis(); axis->append(categories); chart->setAxisY(axis, series); chart->legend()->setVisible(true); chart->legend()->setAlignment(Qt::AlignRight); QCategoryAxis *XAxisCategory = new QCategoryAxis; XAxisCategory->setMin(0); XAxisCategory->setMax(5); XAxisCategory->append("1",1); XAxisCategory->append("2",2); XAxisCategory->append("3",3); XAxisCategory->append("4",4); XAxisCategory->append("5",5); XAxisCategory->setLabelsPosition(QCategoryAxis::AxisLabelsPositionOnValue); chart->setAxisX(XAxisCategory,series); QChartView *chartView = new QChartView(chart); chartView->setRenderHint(QPainter::Antialiasing); QMainWindow window; window.setCentralWidget(chartView); window.resize(800, 300); window.show(); return a.exec(); }