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

How to add text in chartview in Qml



  • I need to have customized label for x and y axis in chartview in QMl.How can i add the text inside chartview



  • hi @Lucky93 if i got your problem you want to denote x and y axis with some name....

    here is a small example:

    import QtQuick 2.9
    import QtQuick 2.0
    import QtCharts 2.0
    import QtQuick.Window 2.2
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        color:"black"
    Rectangle{
    
        width:300
        height:300
        color:"black"
            ChartView {
                backgroundColor: "black"
                height: 30
                width:30
                title: "Spline"
                anchors.fill: parent
                antialiasing: true
                ValueAxis {
                    id: xAxis
                  titleText: "humidity"
                    min: 0
                    max: 10
                }
                ValueAxis {
                    id: yAxis
                    min: 0
                    max: 10
                     titleText: "tempreature"
                }
                SplineSeries {
                    name: "SplineSeries"
                    axisX:xAxis
                    axisY:yAxis
    
                    XYPoint { x: 0; y: 0.0 }
                    XYPoint { x: 1.1; y: 3.2 }
                    XYPoint { x: 1.9; y: 2.4 }
                    XYPoint { x: 2.1; y: 2.1 }
                    XYPoint { x: 2.9; y: 2.6 }
                    XYPoint { x: 3.4; y: 2.3 }
                    XYPoint { x: 4.1; y: 3.1 }
                }
            }
    }
        }
    

    here I am using titleText: "humidity" and titleText: "tempreature" to add text to my axis

    ValueAxis {
                    id: xAxis
                  titleText: "humidity"
                    min: 0
                    max: 10
                }
                ValueAxis {
                    id: yAxis
                    min: 0
                    max: 10
                     titleText: "tempreature"
                }
    

    Result:

    0_1549518900556_53f3595a-f8f7-4dee-8c7e-a86f604e62b8-image.png

    here you can see humidity and tempreature is added..



  • not the title of the x and y axis ,
    i need to add text inside the chartview grid ,relative to x and y of the axis



  • @Lucky93
    as you said relative to x and y axis...
    something like this

    0_1549522464140_1152c4a5-7560-4bfe-8982-add3a86db40d-image.png



  • no not associated to the spline series,
    for example i need to have some random text above the wave like " current data plotted below"



  • ok.
    I ll try to find some way if I got something I ll let you know...


Log in to reply