QChart QChartView reflesh when the QComboBox Changes
-
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());
}