Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Margins in a bar chart Grid <QtCharts>

Margins in a bar chart Grid <QtCharts>

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 991 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Josz
    wrote on last edited by
    #1

    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.png

    I 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();
    }
    
    
    1 Reply Last reply
    0
    • J Offline
      J Offline
      Josz
      wrote on last edited by
      #2

      I answer myshelf,

      I found a solution in another direction;
      Simply making the bar width bigger

       QHorizontalStackedBarSeries *series = new QHorizontalStackedBarSeries();
      
       series->setBarWidth(0.9); //where 1 fill the grid
      
      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved