Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. PyQt5.QtChart - How to display labels in bar instead of as legends?
Forum Updated to NodeBB v4.3 + New Features

PyQt5.QtChart - How to display labels in bar instead of as legends?

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 2 Posters 1.1k 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.
  • PatitotectiveP Offline
    PatitotectiveP Offline
    Patitotective
    wrote on last edited by Patitotective
    #1

    I'm creating a QHorizontalStackedBarSeries and i want the legend (where are all bar sets categories, in this case: vegetables, grains, oils and fats, etc.) instead of being upside, all separate labels (of the legend) in it's respectively bar.
    Like setLabelVisible() in QPieSeries's slices:
    Screenshot from 2021-08-20 17-42-37.png

    This is my actual QHorizontalStackedBarSeries:
    Screenshot from 2021-08-20 17-32-18.png
    So Vegetables will appear in the blue part and so on.


    This is want i want to achieve:
    1770ae0c-c1b1-4261-b366-75dc4c635868-image.png

    eyllanescE 1 Reply Last reply
    0
    • PatitotectiveP Patitotective

      I'm creating a QHorizontalStackedBarSeries and i want the legend (where are all bar sets categories, in this case: vegetables, grains, oils and fats, etc.) instead of being upside, all separate labels (of the legend) in it's respectively bar.
      Like setLabelVisible() in QPieSeries's slices:
      Screenshot from 2021-08-20 17-42-37.png

      This is my actual QHorizontalStackedBarSeries:
      Screenshot from 2021-08-20 17-32-18.png
      So Vegetables will appear in the blue part and so on.


      This is want i want to achieve:
      1770ae0c-c1b1-4261-b366-75dc4c635868-image.png

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      @Patitotective please provide a minimal and reproducible example

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      PatitotectiveP 1 Reply Last reply
      0
      • eyllanescE eyllanesc

        @Patitotective please provide a minimal and reproducible example

        PatitotectiveP Offline
        PatitotectiveP Offline
        Patitotective
        wrote on last edited by
        #3

        @eyllanesc here is:

        import sys
        
        from PyQt5.QtWidgets import QMainWindow, QApplication
        from PyQt5.QtChart import QHorizontalStackedBarSeries, QBarSet, QChart, QBarCategoryAxis, QChartView
        from PyQt5.QtGui import QPainter
        
        class MainWindow(QMainWindow):
            def __init__(self, parent=None):
                super().__init__(parent)
        
                horizontal_stacked_bar_chart = self.create_horizontal_stacked_bar_chart()
                self.setCentralWidget(horizontal_stacked_bar_chart)
        
            def create_horizontal_stacked_bar_chart(self):
                series =  QHorizontalStackedBarSeries()
        
                for food, food_value in {"Vegetables": 100, "Grains": 200, "Fruits": 150, "Protein": 50}.items():
                    food_set = QBarSet(food)
        
                    food_set << food_value
        
                    series.append(food_set)
        
                chart = QChart()
                chart.addSeries(series)
        
                chart.createDefaultAxes()
                
                chart.axisY(series)
        
                chart_view = QChartView(chart)
                chart_view.setRenderHint(QPainter.Antialiasing)
        
                return chart_view
        
        if __name__ == "__main__":
            app = QApplication(sys.argv)
        
            window = MainWindow()
            window.show()
        
            sys.exit(app.exec_())
        
        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