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 add labels on X axis and Y axis of a QChart?
Forum Updated to NodeBB v4.3 + New Features

How to add labels on X axis and Y axis of a QChart?

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

    This is how the chart ends up looking: 8793f4bc-d68b-43c0-863d-11ca3a40d8e7-image.png

    Mind you that I'm calling this method for the labels:

    def add_axis_labels(self):
           # Create a custom label for the X-axis
           x_axis_label = QGraphicsTextItem("Niveles de pH")
           x_axis_label.setFont(QFont("Arial", 10))
           x_axis_label.setDefaultTextColor(Qt.white)
           x_axis_label.setPos(self.chart.plotArea().center().x(), self.chart.plotArea().bottom() + 230)
           x_axis_label.setRotation(-90)
           self.chart.scene().addItem(x_axis_label)
    
           # Create a custom label for the Y-axis
           y_axis_label = QGraphicsTextItem("Muestras")
           y_axis_label.setFont(QFont("Arial", 10))
           y_axis_label.setDefaultTextColor(Qt.white)
           y_axis_label.setPos(310, 330)
           self.chart.scene().addItem(y_axis_label)
    

    It's a bit more tedious and I was recommended to use setTitleText() instead but it doesn't seem to work somehow. I'm using PyQt5 so I'm not sure if only works on older versions. Any advice?

    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