Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Label data points with vertical text (QChart)

Label data points with vertical text (QChart)

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 3.2k 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.
  • D Offline
    D Offline
    delos
    wrote on 18 Oct 2019, 08:07 last edited by
    #1

    Hi

    I writing a code that plots two spline graphs using QChartView and QChart. Inside that chart I wanted to add some rectangles without succees. In fact, I managed to add such rectangles with QGraphicsRectItem but they won't rescale when I resize the main window. Overriding with resizeEvent makes it all too slow.
    Therefore, I used QScatterSeries to create a data series in the chart that look like rectangles. Now I nedd to label them with some text.
    I activated the labels with setPointLabelVisible(true) and gave them a text using setPointLabelsFormat("text").
    My question now is, is there a way to make the text apear in vertical direction? Otherwise the text would overlap and therefore not be readable anymore.
    I attached a picture to visualize my problem.

    Best regards!
    delos
    sample.png

    P 1 Reply Last reply 18 Oct 2019, 11:56
    0
    • D delos
      18 Oct 2019, 08:07

      Hi

      I writing a code that plots two spline graphs using QChartView and QChart. Inside that chart I wanted to add some rectangles without succees. In fact, I managed to add such rectangles with QGraphicsRectItem but they won't rescale when I resize the main window. Overriding with resizeEvent makes it all too slow.
      Therefore, I used QScatterSeries to create a data series in the chart that look like rectangles. Now I nedd to label them with some text.
      I activated the labels with setPointLabelVisible(true) and gave them a text using setPointLabelsFormat("text").
      My question now is, is there a way to make the text apear in vertical direction? Otherwise the text would overlap and therefore not be readable anymore.
      I attached a picture to visualize my problem.

      Best regards!
      delos
      sample.png

      P Offline
      P Offline
      Pl45m4
      wrote on 18 Oct 2019, 11:56 last edited by Pl45m4
      #2

      @delos

      I guess you have to write your own vertical Label-class and paint it above your data point manually.

      https://stackoverflow.com/questions/9183050/vertical-qlabel-or-the-equivalent

      From there:

      void LabelWidget::paintEvent(QPaintEvent*)
      {
          QPainter painter(this);
          painter.setPen(Qt::black);
          //... Need an appropriate call to painter.translate() for this to work properly
          painter.rotate(90);
          painter.drawText(QPoint(0,0), _text);
      }
      

      Is it necessary to show the text at all time? Something like a ToolTip ( triggered by mouseHover over data point) might solve your problem?!


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • D Offline
        D Offline
        delos
        wrote on 18 Oct 2019, 13:24 last edited by
        #3

        @Pl45m4

        Thanks for your answer. I tried things like using my own text objects but they won't scale with the data points. Mayby I didn't assign the to the data correctly. Actually I don't know how to d this ;)

        The tool tips are in fact a great idea. Could you let me know how to do this?

        Cheers
        delos

        P 1 Reply Last reply 18 Oct 2019, 13:35
        0
        • D delos
          18 Oct 2019, 13:24

          @Pl45m4

          Thanks for your answer. I tried things like using my own text objects but they won't scale with the data points. Mayby I didn't assign the to the data correctly. Actually I don't know how to d this ;)

          The tool tips are in fact a great idea. Could you let me know how to do this?

          Cheers
          delos

          P Offline
          P Offline
          Pl45m4
          wrote on 18 Oct 2019, 13:35 last edited by Pl45m4
          #4

          @delos

          There is this signal... (I've never used this before, but it should work)

          You connect your funtion to it and display your custom tooltip bubble with your information.

          https://stackoverflow.com/questions/51085719/showing-tooltip-in-a-qt-chart-with-multiple-y-axes

          @delos said in Label data points with vertical text (QChart):

          they won't scale with the data points

          If you resize the whole window or if you add more data points to your ScatterSeries?


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          D 1 Reply Last reply 18 Oct 2019, 13:43
          0
          • P Pl45m4
            18 Oct 2019, 13:35

            @delos

            There is this signal... (I've never used this before, but it should work)

            You connect your funtion to it and display your custom tooltip bubble with your information.

            https://stackoverflow.com/questions/51085719/showing-tooltip-in-a-qt-chart-with-multiple-y-axes

            @delos said in Label data points with vertical text (QChart):

            they won't scale with the data points

            If you resize the whole window or if you add more data points to your ScatterSeries?

            D Offline
            D Offline
            delos
            wrote on 18 Oct 2019, 13:43 last edited by
            #5

            @Pl45m4

            Both, whe I rescale and when I add more data points out of range.

            P 1 Reply Last reply 18 Oct 2019, 13:55
            0
            • D delos
              18 Oct 2019, 13:43

              @Pl45m4

              Both, whe I rescale and when I add more data points out of range.

              P Offline
              P Offline
              Pl45m4
              wrote on 18 Oct 2019, 13:55 last edited by
              #6

              @delos

              Then using tooltips should fix it, because the QXYSeries::hovered signal will send the point and the state (true / false = mouse over point / mouse left data point).
              You "only" need to map your tooltip data (label text) to your data points. Implementing the tooltip functionality might be not that easy but I dont see any other way, if using the default labels doesn't work for you.


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              1
              • D Offline
                D Offline
                delos
                wrote on 18 Oct 2019, 13:57 last edited by
                #7

                Thanks @Pl45m4

                I'll try but it might take a while since I am just starting.
                When I'am done, I will report on my success or failure.

                Cheers
                delos

                1 Reply Last reply
                0

                3/7

                18 Oct 2019, 13:24

                • Login

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