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

ChartView & AreaSeries



  • I'm developing an Area chart in QML an QT c++.
    I have a timer and at every timeout, my QT class (myChart object) appends a new value to the serei.
    I wanto to fill the chart area, so I'm using AreaSeries, but I've got a problem about this point: I have to use a gradient color and I don't know how do it.
    I tryed to build the color in QT like a property and passing it to the chart, but the final result is that the new color is apply on whole area and not on the new sample.

    This is my code:
    @
    ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Connections {
        target: myChart
        onWValueChanged: {
            lineSeries1.append(myChart.wValue.x, myChart.wValue.y)
        }
    }
    ChartView {
        id: chartView
        anchors.fill: parent
        antialiasing: true
    
        ValueAxis {
            id: valueAxisY
            min: 0
            max: 4
            tickCount: 5
            labelFormat: "%.0f"
        }
    
        ValueAxis {
            id: valueAxisX
            min: 2000
            max: 2000 + myChart.maxXval
            tickCount: 12
            labelFormat: "%.0f"
        }
    
        LineSeries {
            id: series
            axisX: valueAxisX
            axisY: valueAxisY
    
            Component.onCompleted: {
                for(var i = 0;i < myChart.serieSize();i ++) {
                    series.append(myChart.getX(i), myChart.getY(i));
                }
            }
        }
    
        AreaSeries {
            id: russia2
            name: "Russian2"
            color: myChart.fillColor//"#FFD52B1E"
            borderColor: myChart.fillColor//"#FF0039A5"
            borderWidth: 3
            axisX: valueAxisX
            axisY: valueAxisY
            upperSeries:LineSeries {
                id: lineSeries1
                name: "signal 1"
            }
        }
    }
    

    }
    @

    myChart is the QT C++ object used to update the serie an the color.

    Could someone help me to find a solution?

    Many thanks in advance for your support.

    Chobin


  • Moderators

    Hi @Chobin,

    I am not entirely sure what you mean here, what part of it are you trying to apply the gradient to exactly?



  • Hi @AndyS

    Thanks for your reply. I'd like applying the gradient to the AreaSeries: name "Russian2.
    So I created a c++ class where I defined a property color, "fillColor", and at every sample I changed it. At every sample a signal is emitted and the new color is apply to the AreaSeries "Russian2". The problem is that the new color is not apply from the current sample, but from the first to latest sample.

    Is there a way to solve the problem?

    Many thanks.

    Best Regards,

    chobin


  • Moderators

    Hi @Chobin,

    Ah, I understand you now. This is not possible using AreaSeries unfortunately as it only takes a color, and you need to be able to pass a gradient here via a brush. So the only way to do that would be to modify Qt Charts. What I suggest you do is open a feature request for this via JIRA


  • Moderators

    @AndyS said in ChartView & AreaSeries:

    So the only way to do that would be to modify Qt Charts.

    From my point of view, this is pretty much futile as it'd mean hacking at the Qt's sources. QtCharts does not provide for means to extend or modify the behavior, drawing or even adding chart types. Everything is buried in the private classes and the only thing one could override is a couple of setters.


  • Moderators

    @kshegunov said in ChartView & AreaSeries:

    @AndyS said in ChartView & AreaSeries:

    So the only way to do that would be to modify Qt Charts.

    From my point of view, this is pretty much futile as it'd mean hacking at the Qt's sources. QtCharts does not provide for means to extend or modify the behavior, drawing or even adding chart types. Everything is buried in the private classes and the only thing one could override is a couple of setters.

    I meant that you would need to modify the sources directly, not by subclassing. I agree the only way is to override a couple of setters. Thinking about it, in theory, it might be possible to try and get access to the item used directly (since it likely a QGraphicsItem) so you might be able to call setBrush() on it directly. But I didn't mean that you can do this by subclassing at least, Qt Charts does not provide a means in that regard.


Log in to reply