Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Learning
  3. Qt in Education
  4. QChart QChartView reflesh when the QComboBox Changes
Qt 6.11 is out! See what's new in the release blog

QChart QChartView reflesh when the QComboBox Changes

Scheduled Pinned Locked Moved Unsolved Qt in Education
2 Posts 2 Posters 986 Views 2 Watching
  • 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.
  • O Offline
    O Offline
    OguzhanOzturk
    wrote on last edited by
    #1

    I have a vector. I want to show data the vector on the QChart. But I only show first QComboBox item's data. How can I reflesh QChart. I shared my Code Part. Thank you so much. I did some Debug. When I changed the QCombobox selected item, I observed , The code entered the İf condition, but the QChartView did not change. The graphic only shows the first value selected in the QCombobox, it is not updated when I change it.

    delete this->series;
    this->chart->removeAllSeries();
    this->series=new QLineSeries();
    if(GraphName=="Distance(m) - Height(cm)")
    {
    foreach(auto bullet, balsim) {
    this->series->append(bullet.getDistance(), bullet.getHeight());
    }
    }
    else if (GraphName=="Distance(m) - Deflection(cm)")
    {
    foreach(auto bullet, balsim) {
    this->series->append(bullet.getDistance(), bullet.getDeflection());
    }
    }
    else if (GraphName=="Distance(m) - Velocity(fps)")
    {
    foreach(auto bullet, balsim) {
    this->series->append(bullet.getDistance(), bullet.getTotalVelocity());
    }
    }
    else if (GraphName=="Time(s) - Distance(m)")
    {
    foreach(auto bullet, balsim) {
    this->series->append(bullet.getTime(), bullet.getDistance());
    }
    }
    else if (GraphName=="Time(s) - Velocity(fps)")
    {
    foreach(auto bullet, balsim) {
    this->series->append(bullet.getTime(), bullet.getTotalVelocity());
    }
    }
    else if(GraphName=="Time(s) - Height(cm)")
    {
    foreach(auto bullet, balsim) {
    this->series->append(bullet.getTime(), bullet.getHeight());
    }
    }
    delete this->chart;
    this->chart=new QChart();
    QFont font;
    font.setPixelSize(18);
    this->chart=new QChart();
    this->chart->legend()->hide();
    this->chart->removeSeries(this->series);
    this->chart->addSeries(this->series);
    this->chart->createDefaultAxes();
    this->chart->axes(Qt::Horizontal).first()->setLabelsColor(QColor("#8a8c9d"));
    this->chart->axes(Qt::Vertical).first()->setLabelsColor(QColor("#8a8c9d"));
    this->chart->axes(Qt::Horizontal).first()->setLabelsFont(font);
    this->chart->axes(Qt::Vertical).first()->setLabelsFont(font);
    this->chart->setBackgroundBrush(QBrush(QColor("transparent")));
    delete this->chartView;
    this->chartView=new QChartView(chart);
    this->chartView->setRenderHint(QPainter::Antialiasing);
    this->chartView->setParent(ui->horizontalFrame);
    this->chartView->setBackgroundBrush(QBrush(QColor(39,43,74)));
    this->chartView->setBackgroundRole(QPalette::Background);
    this->chartView->setMinimumSize(1251,631);
    this->chartView->setMaximumSize(1251,631);
    this->chartView->setStyleSheet("QChartView{color:green;border: 1px }");

    When the QComboBox is changed I call this function again.

    void PistolsPage::on_comboBox_Axexes_currentIndexChanged(int index)
    {
    //on_btnCalculate_clicked();
    drawChart(balsim,ui->comboBox_Axexes->currentText().toStdString());
    }

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Please do not post the same question in multiple sub forum one is enough.

      Duplicate

      Closing this one

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

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