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. formatting a ChartView
Forum Updated to NodeBB v4.3 + New Features

formatting a ChartView

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 2 Posters 744 Views 2 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    Customer wants something that looks like this:
    chart.PNG
    The very small dark blue rectangle is supposed to be the bar itself; the light blue is the background (accent).

    So, I was thinking of using a ChartView for this.

        ChartView {
            height: 300
            width: 100
            anchors.top: spacer2.bottom
            anchors.horizontalCenter: parent.horizontalCenter
            legend.visible: false
            antialiasing: true
    
            StackedBarSeries {
                id: mySeries
                axisYRight: BarCategoryAxis {
                    visible: true
                    labelsVisible: true
                }
                barWidth: 0.96
                BarSet {
                    values: [0.1]
                    color: reagentPlotColor
                }
                BarSet {
                    values: [1.9]
                    color: reagentPlotBackgroundColor
                }
            }
        }
    

    I'm having trouble getting it properly formatted, though:
    mychart.PNG

    So:

    1. does a ChartView seem like a good way to do this, or is it overkill?
    2. how do I get the scale to appear on the right (or at all)?
    3. any idea why the chart isn't honoring my request for a width of 100 px?

    Thanks...

    1 Reply Last reply
    0
    • mzimmersM Offline
      mzimmersM Offline
      mzimmers
      wrote on last edited by
      #2

      So, after some experimentation, I've managed to get it to look like this:chart.PNG
      Here's the code:

          ChartView {
              width: parent.width
              height: 300
              anchors.horizontalCenter: parent.horizontalCenter
              antialiasing: true
              title: 'Reagents Level'
      
              StackedBarSeries {
                  id: mySeries
                  labelsVisible: false
                  axisY: BarCategoryAxis {
                      gridVisible: false
                  }
                  barWidth: 0.33
                  BarSet {
                      values: [0.1]
                      color: reagentPlotColor
                  }
                  BarSet {
                      values: [1.9]
                      color: reagentPlotBackgroundColor
                  }
              }
          }
      

      So, some specific questions:

      1. is there such a thing as an individual Bar, or is it correct to use BarSet when you only have one?
        How do I get rid of:
      • the color legend above the bar
      • the number "1" below the bar
      • the vertical line on the left
      1. can I get a scale indicator on the right side, and if so, can I have control over the granularity?

      Thanks...

      1 Reply Last reply
      0
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        Some more experimentation; my chart now looks like this:

        chart.PNG

        Any suggestions on getting the "1" and the vertical line on the left to disappear? I mean, I could just draw white rectangles over them, but...

        Thanks...

        1 Reply Last reply
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4

          Define an axis for the x axis. It has settings to hide it.

          C++ is a perfectly valid school of magic.

          mzimmersM 1 Reply Last reply
          1
          • fcarneyF fcarney

            Define an axis for the x axis. It has settings to hide it.

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            @fcarney oh, that's very helpful:

                  ValueAxis {
                    id: valueAxisX
                    labelsVisible: false
                    gridVisible: false
                  }
            

            This gets rid of both that "1" AND the left side line. No need for the rectangle hacks!

            So...where was that "1" coming from, anyway? It wasn't a label; I say this because when I remove the "labelsVisible: false" I get this:
            chart.PNG

            What would be ideal is if I could change that 1 to my own text. Customer wants the title below the chart, not above it, which doesn't seem to be an option in ChartView, but if I could repurpose that "1" I could kill two birds with one stone.

            Thanks...

            1 Reply Last reply
            0
            • fcarneyF Offline
              fcarneyF Offline
              fcarney
              wrote on last edited by
              #6

              https://doc.qt.io/qt-5/qml-qtcharts-abstractaxis.html#alignment-prop

              I don't know what the key/legend is called in the chart. Look around and see if it has a way to move it. The above link shows how to align an axis. Not sure if that helps or not.

              C++ is a perfectly valid school of magic.

              mzimmersM 1 Reply Last reply
              1
              • fcarneyF fcarney

                https://doc.qt.io/qt-5/qml-qtcharts-abstractaxis.html#alignment-prop

                I don't know what the key/legend is called in the chart. Look around and see if it has a way to move it. The above link shows how to align an axis. Not sure if that helps or not.

                mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #7

                @fcarney yeah, I think I can't use the legend, because that includes the little colored box which I don't want.

                It's still a mystery to me where that 1 is/was coming from, but I think I'll just superimpose a label (hacky, hacky).

                Thanks for the assistance.

                fcarneyF 1 Reply Last reply
                0
                • mzimmersM mzimmers

                  @fcarney yeah, I think I can't use the legend, because that includes the little colored box which I don't want.

                  It's still a mystery to me where that 1 is/was coming from, but I think I'll just superimpose a label (hacky, hacky).

                  Thanks for the assistance.

                  fcarneyF Offline
                  fcarneyF Offline
                  fcarney
                  wrote on last edited by
                  #8

                  @mzimmers I think the 1 comes from not explicitly creating an axis. So it made one up. Probably default axis or something.

                  C++ is a perfectly valid school of magic.

                  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