Solved QChartView does not draw multiple curves
-
class FCurveView : public QChartView { Q_OBJECT public: explicit FCurveView( QWidget * parent = nullptr, const QString & legend_name = QString( "" ) ); virtual ~FCurveView(); void addData( const float x, const float y, const unsigned idx = 0 ); void addLineSeries( const QColor & color, const QString & legend_name = QString( "" ) ); void addLogYData( const float x, const float y, const unsigned idx = 0 ); void clear(); void setCurveTitle( const QString title ); void setTitleText( const QString title_x, const QString title_y ); void setXRanges( const float min_x, const float max_x ); void setYRanges( const float min_y, const float max_y ); private: std::vector< QLineSeries * > m_vecLineSeries; }; FCurveView::FCurveView( QWidget * parent, const QString & legend_name ) : QChartView( new QChart(), parent ) { setRenderHint( QPainter::Antialiasing ); addLineSeries( Qt::red, legend_name ); chart()->createDefaultAxes(); chart()->axisX()->setTitleText( QString( "X" ) ); chart()->axisY()->setTitleText( QString( "Y" ) ); chart()->legend()->attachToChart(); chart()->legend()->setVisible( true ); chart()->legend()->setAlignment( Qt::AlignRight ); } void FCurveView::addData( const float x, const float y, const unsigned idx ) { m_vecLineSeries[ idx ]->append( x, y ); } void FCurveView::addLineSeries( const QColor & color, const QString & legend_name ) { QLineSeries * line_series = new QLineSeries(); line_series->setName( legend_name ); line_series->setPen( QPen( color, 1, Qt::SolidLine ) ); chart()->addSeries( line_series ); m_vecLineSeries.push_back( line_series ); }
5 sets of data are dynamically generated and fed into the curveview class. Only the first curve is drawn. I can see all 5 legends and the first curve. Why do not the other four curves show up? These sets of data are in the similar range. Any comments?
-
No comments?
-
Can you show us how you call
FCurveView::addData
? -
I feel like I ran into a similar issue awhile back but it has been awhile.
Try adding an axis to your series that comes from the chart so they all have the same axis. One for x-dir and y-dir.
-
@MrShawn You made my day, Shawn. Many thanks.