Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QChartView does not draw multiple curves
Forum Updated to NodeBB v4.3 + New Features

QChartView does not draw multiple curves

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 772 Views
  • 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.
  • JoeCFDJ Offline
    JoeCFDJ Offline
    JoeCFD
    wrote on last edited by VRonin
    #1
    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?

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      No comments?

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        Can you show us how you call FCurveView::addData?

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MrShawn
          wrote on last edited by MrShawn
          #4

          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.

          JoeCFDJ 1 Reply Last reply
          1
          • M MrShawn

            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.

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by
            #5

            @MrShawn You made my day, Shawn. Many thanks.

            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