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. Qchart formatLabel QML

Qchart formatLabel QML

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

    Hello everybody,

    I'm developing a linear chart using qml with qt creator, and I'd like to append a character to every Y axis label. For example I want append "°C" to the number 15: the final resul should be 15°C. I tried to use the following QML code, but the resul is 15?C.

    ValueAxis {
    min: 0
    max: 100
    labelFormat: "%d%1".arg("°C)
    }

    Does someone help me?
    Many thanks in advance.

    Best Regards,
    Chobin

    DiracsbracketD 1 Reply Last reply
    0
    • C Chobin

      Hello everybody,

      I'm developing a linear chart using qml with qt creator, and I'd like to append a character to every Y axis label. For example I want append "°C" to the number 15: the final resul should be 15°C. I tried to use the following QML code, but the resul is 15?C.

      ValueAxis {
      min: 0
      max: 100
      labelFormat: "%d%1".arg("°C)
      }

      Does someone help me?
      Many thanks in advance.

      Best Regards,
      Chobin

      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by Diracsbracket
      #2

      @Chobin
      As the documentation states, this is not supported by the ValueAxis of the QtCharts module.
      https://doc.qt.io/qt-5/qml-qtcharts-valueaxis.html#labelFormat-prop

      Whenever you try to use a second format specifier in .arg(), you will get a message like:

      QString::arg: Argument missing
      

      This is unlike the labelFormat property in the QtDataVisualization module, see for example
      https://doc.qt.io/qt-5.11/qtdatavisualization-qmlbars-example.html, where the following does work:

      labelFormat: "%d \u00B0C"
      

      In your case, an annoying workaround would be to use a CategoryAxis instead.

      e.g.

                  axisX: CategoryAxis {
                      min: 0
                      max: 4
                      labelsPosition: CategoryAxis.AxisLabelsPositionOnValue
                      CategoryRange {
                          label: "1 \u00B0C"
                          endValue: 1
                      }
                      CategoryRange {
                          label: "2 \u00B0C"
                          endValue: 2
                      }
                      CategoryRange {
                          label: "3 \u00B0C"
                          endValue: 3
                      }
                      CategoryRange {
                          label: "4 \u00B0C"
                          endValue: 4
                      }
                  }
      

      To be practical, you may need to create this one dynamically instead...

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved