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. How to add QAreaSeries to Qtchart?
Qt 6.11 is out! See what's new in the release blog

How to add QAreaSeries to Qtchart?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 272 Views 1 Watching
  • 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.
  • P Offline
    P Offline
    preddy
    wrote on last edited by
    #1

    Hello,

    I have the following code in which I create Qtchart, and whenever the reset button is pushed the graph should be shown with the QAreaSeries plotted on it.

    main::main(QWidget *parent) :
    	QDialog(parent),
    	ui(new Ui::main)
    {
    	ui->setupUi(this);
    	setWindowTitle("Test Config");
    
    	p_MainWindow = parent;	
    
    	qChart = new QChart();
    	myChartView = new QChartView(qChart);
    	qAxisX = new QValueAxis;
    	qAxisY = new QValueAxis;
    	qAxisX->setRange(0, 30);
    	qAxisY->setRange(0, 10000);
    
    }
    
    void main::maingraph()
    {
    	for (int k = 1; k < 3; k++)
    	{
    		if (true)
    		{
    			switch (k)
    			{
    			case 1:
    				series0 = new QLineSeries();
    				series1 = new QLineSeries();
    
    				*series0 << QPointF(1, 6) << QPointF(1, 10);
    				*series1 << QPointF(4, 6) << QPointF(4, 10);
    
    				series = new QAreaSeries(series0, series1);
    
    				AddBlockToGraph(series);
    
    				break;
    			case 2:
                                    series0 = new QLineSeries();
    				series1 = new QLineSeries();
    
    				*series0 << QPointF(10,16) << QPointF(10, 20);
    				*series1 << QPointF(14, 16) << QPointF(14, 20);
    
    				series = new QAreaSeries(series0, series1);
    
    				AddBlockToGraph(series);
    				break;
    			default:
    				break;
    			}
    		}
    	}
    }
    
    void main::AddBlockToGraph(QAreaSeries *series)      //I get this QAreaSeries from Switch cases
    {
    //This is the place where I need help. I should add QAreaSeries to the graph after every switch case.
    
    	myChartView->chart()->mapToParent(/*what to add here*/,series);
    	qChart->setAxisX(qAxisX, series);
    	qChart->setAxisY(qAxisY, series);
    
    	ui->verticalLayout->addWidget(myChartView);
    }
    
    void main::on_pushButton_clicked()               //the reset button function
    {
    	clearLayout(ui->verticalLayout, true);
    
    	maingraph(m_tcGFullXmlConfig);
    }
    

    Thank you.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @preddy said in How to add QAreaSeries to Qtchart?:

      QAreaSeries

      Hi
      Im not sure what that
      myChartView->chart()->mapToParent
      is about ?
      i would expect something like
      myChartView->chart()->addSeries(series);

      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