how to deal with two QBarSeries overlapping ?



  • Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
    {
    ui->setupUi(this);
    mMainLayout = new QHBoxLayout(this);
    mChartView = new QChartView(this);

    mMainLayout->addWidget(mChartView);
    
    mChart = new QChart();
    mChartView->setChart(mChart);
    
    xAxis = new QValueAxis;
    mChart->addAxis(xAxis, Qt::AlignBottom);
    xAxis->setRange(0, 5);
    
    yLeftAxis = new QValueAxis;
    mChart->addAxis(yLeftAxis, Qt::AlignLeft);
    yLeftAxis->setRange(1, 5);
    
    yRightAxis = new QValueAxis;
    mChart->addAxis(yRightAxis, Qt::AlignRight);
    yRightAxis->setRange(10, 90);
    

    // twoSeries();
    oneSeries();
    this->resize(800, 600);
    }

    void Widget::oneSeries(){
    QBarSeries *barSeries2 = new QBarSeries(mChart);
    mChart->addSeries(barSeries2);
    barSeries2->attachAxis(xAxis);
    barSeries2->attachAxis(yRightAxis);
    barSeries2->setBarWidth(0.1);
    QBarSet *rightData = new QBarSet("right");
    rightData->append(QList<qreal>() << 10 << 40 << 30 << 40 << 20);
    barSeries2->append(rightData);
    barSeries2->setOpacity(0.5);

    mChart->setGeometry(100, 30, 40, 50);
    mChart->setPos(QPointF(100, 20));
    QBarSeries *barSeries1 = new QBarSeries(mChart);
    mChart->addSeries(barSeries1);
    
    barSeries1->attachAxis(xAxis);
    barSeries1->attachAxis(yLeftAxis);
    QBarSet *leftData = new QBarSet("left");
    leftData->append(QList<qreal>() << 1 << 2 << 3 << 4 << 4);
    barSeries1->append(leftData);
    barSeries1->setOpacity(0.5);
    barSeries1->setBarWidth(0.5);
    

    }

    void Widget::twoSeries(){
    QBarSeries *barSeries2 = new QBarSeries(mChart);
    mChart->addSeries(barSeries2);
    barSeries2->attachAxis(xAxis);
    barSeries2->attachAxis(yRightAxis);
    barSeries2->setBarWidth(0.1);
    QBarSet *rightData = new QBarSet("right");
    rightData->append(QList<qreal>() << 10 << 40 << 30 << 40 << 20);
    barSeries2->append(rightData);
    barSeries2->setOpacity(0.5);

    QBarSeries *barSeries1 = new QBarSeries(mChart);
    mChart->addSeries(barSeries1);
    
    barSeries1->attachAxis(xAxis);
    barSeries1->attachAxis(yLeftAxis);
    QBarSet *leftData = new QBarSet("left");
    leftData->append(QList<qreal>() << 1 << 2 << 3 << 4 << 4);
    barSeries1->append(leftData);
    barSeries1->setOpacity(0.5);
    barSeries1->setBarWidth(0.5);
    

    }

    Widget::~Widget()
    {
    delete ui;
    }


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.