How to dynamically update Stacked Bar Series Values after initialize the QChart

23 views Asked by At

I have a Chart Class in chart.h header file:

class Chart{
public:
   void initialize();
   void update(double, double);
}

and implementation of Chart class in chart.cpp source file:

void Chart::initialize(){
   QBarSet* expected = new QBarSet("expected");
   QBarSet* unexpected = new QBarSet("unexpected");

   *expected << 0;
   *unexpected << 0;

   QStackedBarSeries *series = new QStackedBarSeries();
   series->append(expected);
   series->append(unexpected);

   QChart *chart = new QChart();
   chart->addSeries(series);

   QChartView *cw = new QChartView(chart);
   cw->setParent(ui->frame);
}

void Chart::update(double expected, double unexpected){
   *expected << expected;
   *unexpected << unexpected;
}

I created object of class and initialize the bars. When i call the update() function in the code blocks i want to update stacked bar value. But i doesn't work that i wanted like it.

For example, i initialized the bars as a expected = 5 and unexpected = 5 in the first initialize. When i call the update(2, 2) function bars does't adjust to graph or chart view. New value 2 is smaller than 5 and. You know 2 unit is smaller than 5 and new rectangle doesn't fill to all size.

Let's think a rectangle and it's height is 100 px. We have expected = 5 and unexpected = 5. So that QChart will create 2 rectangles and those height will be 50 px. It's okey. But when i update rectangle with update() function new 2 rectangles have 20 px and 20 px. Out of the 2 rectangle there is a gap in 60 px. How to adjust the size of rectangle to all size?

I just the QBarSet::append() function, QBarSet::insert() function but it didn't work. And also i removed bar value and again insert value to bar. But it didn't work again.

How to start stacked bar series and update stacked bar values in Qt. Can you help me friends?

Thanks :)

0

There are 0 answers