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. How to achieve show/hide Qt Charts series by clicking legendmarker in Qt Quick
Forum Updated to NodeBB v4.3 + New Features

How to achieve show/hide Qt Charts series by clicking legendmarker in Qt Quick

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 950 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.
  • Y Offline
    Y Offline
    ynakane
    wrote on last edited by ynakane
    #1

    Hi.

    I want to achieve below example in Qt Quick Project.
    https://doc.qt.io/qt-6/qtcharts-legendmarkers-example.html

    This example uses the QChartView class, but I'm using the QML ChartView Type.
    I don't know how to detect the LegendMarker's Clicked signal from ChartView QML.
    It seems that the LegendMarker cannot be accessed from the QML Legend Type.

    Thank you in advance.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Robbie Ashby
      wrote on last edited by
      #2

      Hi ynakane,

      I was trying to achieve the same thing and was unable to do it using the QML Legend Type. However, I am relatively new to Qt Quick (coming from a widgets background) so may not have been doing things correctly.

      The method I found that did work was creating a custom QML legend. I based this off the tutorial example:

      https://doc.qt.io/qt-6/qtcharts-qmlcustomlegend-example.html

      Change the purpose of the onSelected signal to instead change the series visibility. I also changed the signal so it passed the index instead of the series name. Then in you main QML code connect to the signal like this:

              CustomLegend
              {
                  id: customLegend
                  width: parent.width
                  height: 50
                  anchors.top: chartView.bottom
                  anchors.horizontalCenter: parent.horizontalCenter
                  onSelected:
                  {
                      chartView.series(seriesIndex).visible = !chartView.series(seriesIndex).visible
                  }
              }
      

      I don't know if this is the best method to use but it worked well for me.

      1 Reply Last reply
      0

      • Login

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