Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Spline Chart



  • 52551c4f-52dd-42cf-9f74-2e1b5cf74e1c-image.png

    QChart* QTemperatureChart::createSplineChart()
    {
    	m_pChart = new QChart();
    	m_pChart->setTitle("Spline chart");
    
    	// The lower series initialized to zero values
    	QString name("Series ");
    	int nameIndex = 0;
    
    	m_pSplineSeries = new QSplineSeries(m_pChart);
    	
    	m_pChart->addSeries(m_pSplineSeries);
    
    	m_pChart->addAxis(m_valueAxisX = new QValueAxis(), Qt::AlignBottom);
    	m_pChart->addAxis(m_valueAxisY = new QValueAxis(), Qt::AlignLeft);
    
    	m_pSplineSeries->attachAxis(m_valueAxisX);
    	m_pSplineSeries->attachAxis(m_valueAxisY);
    
    	m_valueAxisX->setTickCount(7);
    	m_valueAxisX->setRange(0, 6);
    	m_valueAxisY->setRange(0, 100);
    
    	//m_pChart->createDefaultAxes();
    	//m_pChart->axes(Qt::Vertical).first()->setRange(0, 10);
    
    	return m_pChart;
    }
    
    void QTemperatureChart::UpdateChart(QPointF point)
    {
    	int randomx = QRandomGenerator::global()->bounded(0, 100);
    	int randomy = QRandomGenerator::global()->bounded(0, 100);
    
    	
    	m_pSplineSeries->append(m_pSplineSeries->count(), randomy);
    	m_pChart->scroll(10, 0);
    }
    

    595b7252-b6f3-495c-9bc2-ed89e3bb5383-image.png

    I want to increase the x-axis by one on the chart, but it's increasing by 0.1.
    And I want to fix the graph in the middle, so I think I can use Scroll.
    But it doesn't work.


Log in to reply