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. QCharts - QLineSeries from independent X and Y arrays
Forum Updated to NodeBB v4.3 + New Features

QCharts - QLineSeries from independent X and Y arrays

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 3.9k 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.
  • ratovariusR Offline
    ratovariusR Offline
    ratovarius
    wrote on last edited by ratovarius
    #1

    Hi,
    What's the best way to plot two arrays in a LineChart with QCharts , one versus the other,

    #define SIZE 100
    int xArray[SIZE];
    int yArray[SIZE];

    Do I have to create a list of QPoints manually from these arrays?
    Is there any way to add xArray or yArray to QLineSeries without modifying the other?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      You can apply some thing simple like follows

      QLineSeries *series0 = new QLineSeries();
      
      series0->append(0,6);
      series0->append(2,4);
      

      chart.addSeries(series0);
      You don't have to create Points.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      4
      • ratovariusR Offline
        ratovariusR Offline
        ratovarius
        wrote on last edited by
        #3

        Thanks for your answer. I'd like to append to QLineSeries the X coordinates independent from the Y coordinates, in your exaplme something like,

        QLineSeries *series0 = new QLineSeries();
        
        int xArray[2] = {0, 2};
        int yArray[2] = {6, 4};
        
        series0->setXData(xArray);
        series0->setYData(yArray);
        

        I want the best way to change X or Y data without modifying the other.

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

          You can set all the points with one of the coordinates at 0 and then use replace()

          for(int i : xArray)
          series0->append(i,0);
          Q_ASSERT(series0->count()>=std::extent<decltype(yArray)>::value);
          for(int i=0;i<std::extent<decltype(yArray)>::value;++i)
          series0->replace(i,series0->at(i).x(),yArray[i]);
          
          

          "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

          ratovariusR 1 Reply Last reply
          1
          • VRoninV VRonin

            You can set all the points with one of the coordinates at 0 and then use replace()

            for(int i : xArray)
            series0->append(i,0);
            Q_ASSERT(series0->count()>=std::extent<decltype(yArray)>::value);
            for(int i=0;i<std::extent<decltype(yArray)>::value;++i)
            series0->replace(i,series0->at(i).x(),yArray[i]);
            
            
            ratovariusR Offline
            ratovariusR Offline
            ratovarius
            wrote on last edited by
            #5

            @VRonin
            Thanks! Thats a way, but what about performance?
            I'd like a way to pass a pointer to the x or y data structure, instead of copying it.
            I am migrating an application that used Qwt. That library had some functions meant for performance like,

            series.setRawSamples(xData, yData, numData);
            painter.drawSeries(&series, from, to);
            

            I know it's a different library, but I need to plot data in an environment with constant change in X or Y data.
            I tried to use a QVXYModelMapper but I didn't find a way to manage the X and Y data from the model in a independent way.

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

              if you can use QVXYModelMapper then it's already done. For example:

              • mapper is QVXYModelMapper
              • i is the index of the point you want to change the Y coordinate for
              • newY is the new value for Y
              mapper.model()->setData(mapper.model()->index(i,mapper.yColumn()), newY);
              

              "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
              1

              • Login

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