How to animate horizontal bar series

32 views Asked by At

I'd like to ask how to animate horizontal bar series in QML.

With PieSeries it works like this:

PieSeries {
            id: _pieSeries

            PieSlice {
                id: _firstSlice
                labelVisible: true
                label: (LifeStyle.overallTension() * 100).toFixed(2) + "%"
                NumberAnimation on value {
                    duration: 500
                    from: 0
                    to:LifeStyle.overallTension()
                }

                labelPosition: PieSlice.LabelInsideHorizontal
                labelColor: "white"
                exploded: true
                explodeDistanceFactor: 0.05
            }

            PieSlice {
                id: _secondSlice
                labelVisible: false
                value: 1 - LifeStyle.overallTension()
            }
        }

But when I try to do this with the HorizontalBarSeries, it does not work, maybe the problem is about array of values, but I am not sure. Code below:

ChartView {
        title: "Title of graphChart"
        anchors.fill: parent
        antialiasing: true
        legend.visible: false

        HorizontalBarSeries {
            id: _barSeries
            axisY: BarCategoryAxis {
                categories: ["Title1", "Title2", "Title3", "Title4", "Title5", "Title6", "Title7", "Title8"]
            }
            BarSet {
                id: barSet
                values: [0, 0, 0, 0, 0, 0, 0, 0]

                NumberAnimation on values {
                    to: [1, 2, 3, 4, 5, 6, 7, 8]
                    duration: 600
                    running: true
                }
            }
        }
    }

So,my question is: how to animate these BarSet values

1

There are 1 answers

0
Erik Nikoyan On

It was so simple that I didn't even notice it. Adding this line: animationOptions: ChartView.SeriesAnimations to the Chart View helped to achieve the desired result