Adding points to a QLineSeries - nothing displayed on chart
-
I'm working in widget space. I create a chart, it shows up with default axes on my GUI. I also create a QLineSeries and assign it to the chart. Later, as data rolls in, I add points to the QLineSeries. But nothing shows up. No line is created. Here is source for instantiating, followed by slot handler source for updating. You can see i rely on QT built in promotion to convert data to qreal.
void SxDiagTECVerificationView::mCreateTemperatureChart()
{
QHBoxLayout* chartLayout = new QHBoxLayout(m_testUI.grpTEC_Chart);
m_temperatureChart = new QChart();
m_temperatureChart->setAnimationOptions(QChart::AllAnimations);
m_temperatureChart->legend()->hide();
m_temperatureChartView = new QChartView(m_temperatureChart);
chartLayout->addWidget(m_temperatureChartView);
m_temperatureLineSeries = new QLineSeries();
m_temperatureChart->addSeries(m_temperatureLineSeries);
m_temperatureChart->createDefaultAxes();
}void SxDiagTECVerificationView::on_timeAndTemperatureUpdate(float temperature, unsigned int elapsedTimeMsec)
{
m_temperatureLineSeries->append(elapsedTimeMsec, temperature);
m_temperatureLineSeries->show();
QApplication::processEvents(QEventLoop::AllEvents);
} -
I figured it out. You must instantiate the line series with a reference to the chart. It is not enough to simply add the series to the chart. I believe that is the fix that finally worked.