Results 1 to 5 of 5

Thread: qchart hide legend for part of series

  1. #1
    Join Date
    Nov 2016
    Posts
    6
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default qchart hide legend for part of series

    Hello,

    I have a QChart which contains 4 line series. I would like to set legend for only two of them. Any suggestions?

    Many thanks.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,719
    Thanks
    259
    Thanked 759 Times in 749 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: qchart hide legend for part of series

    For something in a Qt library, I am disappointed in how poorly QtCharts are designed. It is almost impossible to customize them in any way - there are no virtual methods you can override to customize behavior or add new series types, and all of the implementation is hidden in private classes that are inaccessible and can't be modified without a complete rewrite.

    Your problem is just another example of the "take it or leave it" design philosophy, and I am afraid you are stuck with it. The legend is owned by the chart, and the chart puts an entry on the legend for each series. You can't have a series be visible on the chart without it also being visible in the legend, and vice versa.

    You might want to look at QCustomPlot as an alternative library. The documentation for its legend class seems to indicate that legend items can be made individually visible. See QCPLegend in the documentation.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Mar 2017
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: qchart hide legend for part of series

    Actually, you can do something about your problem.

    The thing is to select the marker inside the legend and set it to be invisible:

    Qt Code:
    1. serie_without_marker = new QLineSeries();
    2. chart.addSeries(serie_without_marker);
    3.  
    4. // we select the marker associated with serie_without_marker
    5. chart.legend().markers(serie_without_marker)[0].setVisible(false);
    To copy to clipboard, switch view to plain text mode 

    I haven't tested it in C++ but this method works with PyQt5.

  4. #4
    Join Date
    Jul 2020
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Post Re: qchart hide legend for part of series

    In Qt c++, you can hide the legend of series using:

    Qt Code:
    1. QChat * myChart = new QChart();
    2. myChart->addSeries(mySeries);
    3. myChart->legend()->hide();
    To copy to clipboard, switch view to plain text mode 
    Last edited by abbaasi69; 12th October 2020 at 17:02. Reason: missing [code] tags

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,719
    Thanks
    259
    Thanked 759 Times in 749 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: qchart hide legend for part of series

    In Qt c++, you can hide the legend of series using:
    This does not answer the original question. The was question was not "How do I hide the legend?", it was "How do I hide -part- of the legend and show other parts (series)?"
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Reading text file line part by part
    By anh5kor in forum Newbie
    Replies: 4
    Last Post: 23rd December 2015, 12:31
  2. How to hide part of a QwtPlot scale?
    By Momergil in forum Qwt
    Replies: 2
    Last Post: 6th February 2013, 20:41
  3. Replies: 2
    Last Post: 23rd June 2012, 19:12
  4. Replies: 2
    Last Post: 23rd August 2011, 13:23
  5. Show/hide part of dialog with resizing.
    By Spockmeat in forum Qt Tools
    Replies: 6
    Last Post: 7th June 2006, 09:22

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.