Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Adding right axis in QtQuick ChartView changes also left axis
Forum Updated to NodeBB v4.3 + New Features

Adding right axis in QtQuick ChartView changes also left axis

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 765 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.
  • M Offline
    M Offline
    MarcW
    wrote on last edited by
    #1

    Hi,

    I want dynamically change LineSeries in a QML ChartView. I'm using Qt 5.7
    For this purpose, I have a variable 'updateChart', which triggers the replacement of existing LineSeries, using removeAllSeries() and createSeries()

    Sometimes, a LineSeries needs to be displayed using a secondary axis (right axis).
    The ChartView createSeries() doesn't allow to assign a right axis to a LineSeries, and from the documentation I cannot find an alternative.

    Additionally, you need to have already an axis before calling the createSeries method.
    Therefor I have declared 3 axes (X, Y left, Y right) in the ChartView for using them in the createSeries call. The min/max values are modified in another view and kept in the 'chartContext'.
    After creation, I change the axisY to axisYRight.

    The problem is that my ChartView displays the same axis (min/max values) on both sides. When I change one of the minima/maxima, it updates to that last value, even mixing the minimum from the left axis with the maximum from the right axis.

    How can I avoid this ?
    Below is my (shortened) code :
    chartContext and dataModel are C++ contexts

    ChartView {
    	id: linechart;
    	anchors.fill: parent;
     
    	property var updateChart: chartContext.updateChart;
     
    	title: chartContext.chartTitle;
    	antialiasing: true;
     
    	ValueAxis {
    		id: xAxis;
    		min: chartContext.minXAxis;
    		max: chartContext.maxXAxis;			
    	}
    	ValueAxis {
    		id: yAxis;
    		min: chartContext.minYAxis;
    		max: chartContext.maxYAxis;
    	}
    	ValueAxis {
    		id: yAxis2;
    		min: chartContext.minYAxis2;
    		max: chartContext.maxYAxis2;
    	}
     
    	onUpdateChartChanged: {
    		linechart.removeAllSeries();
     
    		for (var i = 0; i < dataModel.numberOfSeries; ++i) {			
    			var lineSeries;
    			if (dataModel.axisLocation(i) == "Right") {
    				lineSeries = linechart.createSeries(ChartView.SeriesTypeLine, dataModel.getYLabel(i), xAxis);
    				lineSeries.axisYRight = yAxis2;
    			}
    			else {
    				lineSeries = linechart.createSeries(ChartView.SeriesTypeLine, dataModel.getYLabel(i), xAxis, yAxis);
    			}
    			var point;
    			for (var j = 0; j < dataModel.getNumberOfDataPoints(i); ++j) { 
    				point = lineSeries.append(dataModel.getXValue(i,j), dataModel.getYValue(i,j));
    			}
    			lineSeries.pointsVisible = true;			
    		}
            }
    }
    
    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jose Ramon
      wrote on last edited by
      #2

      I'm working with qt5.9 and I have the same problem. Do you have find any solution?

      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