Skip to content

ChartMixin

Sub classes

Name Children Inherits
Chart
prettyqt.charts.chart
    PolarChart
    prettyqt.charts.polarchart

      Base classes

      Name Children Inherits
      GraphicsWidgetMixin
      prettyqt.widgets.graphicswidget

      â‹” Inheritance diagram

      graph TD
        2717399598["charts.ChartMixin"]
        1217014474["widgets.GraphicsWidgetMixin"]
        1453500865["widgets.GraphicsObjectMixin"]
        3227531497["core.ObjectMixin"]
        2751680898["builtins.object"]
        1638127052["widgets.GraphicsItemMixin"]
        1752462451["widgets.GraphicsLayoutItemMixin"]
        1217014474 --> 2717399598
        1453500865 --> 1217014474
        3227531497 --> 1453500865
        2751680898 --> 3227531497
        1638127052 --> 1453500865
        2751680898 --> 1638127052
        1752462451 --> 1217014474
        2751680898 --> 1752462451

      🛈 DocStrings

      Bases: GraphicsWidgetMixin

      Source code in prettyqt/charts/chart.py
      class ChartMixin(widgets.GraphicsWidgetMixin):
          def __init__(self, *args, **kwargs):
              super().__init__(*args, **kwargs)
              self.max_x = 0
              self.max_y = 0
              self.min_x = 0
              self.min_y = 0
              self.adjust_style_to_palette()
              gui.GuiApplication.styleHints().colorSchemeChanged.connect(
                  self.adjust_style_to_palette
              )
      
          def adjust_style_to_palette(self):
              """Adjusts the chart theme to current Palette.
      
              Checks if palette is dark-ish and applies an appropriate theme to the chart.
              """
              pal = gui.GuiApplication.get_palette()
              style = "Dark" if pal.is_dark() else "Light"
              self.set_theme(style)
      
          def get_axes(
              self,
              orientation: constants.OrientationStr | constants.Orientation | None = None,
              series: charts.QAbstractBarSeries | None = None,
          ) -> list[charts.QAbstractAxis]:
              """Get axes of chart.
      
              Arguments:
                  orientation: Orientation of the axes that should get returned.
                  series: Series to return axes for. Returns all axes if None.
              """
              if orientation is None:
                  orientation = constants.HORIZONTAL | constants.VERTICAL
              return self.axes(constants.ORIENTATION.get_enum_value(orientation), series)
      
          def update_boundaries(self):
              """Set new min/max values based on axis."""
              if axis_x := self.get_axes("horizontal"):
                  self.max_x = axis_x[0].max()
                  self.min_x = axis_x[0].min()
              if axis_y := self.get_axes("vertical"):
                  self.max_y = axis_y[0].max()
                  self.min_y = axis_y[0].min()
      
          def hide_legend(self):
              self.legend().hide()
      
          def show_legend(self):
              self.legend().show()
      
          def get_legend(self) -> charts.Legend:
              return charts.Legend(self.legend())
      
          def set_legend_alignment(
              self, alignment: constants.SideStr | constants.AlignmentFlag
          ):
              """Set alignment of the chart legend."""
              self.legend().setAlignment(constants.SIDES.get_enum_value(alignment))
      
          def set_theme(self, theme_name: ThemeStr | charts.QChart.ChartTheme):
              self.setTheme(THEMES.get_enum_value(theme_name))
      
          def set_margins(self, margins: datatypes.MarginsType):
              margins = datatypes.to_margins(margins)
              self.setMargins(margins)
      
          def set_animation_options(
              self, option: AnimationOptionStr | charts.QChart.AnimationOption
          ):
              self.setAnimationOptions(ANIMATION_OPTIONS.get_enum_value(option))
      
          def apply_nice_numbers(self):
              """Adjust both axis to display nice round numbers."""
              for axis in self.get_axes():
                  axis.applyNiceNumbers()
      
          def zoom_by_factor(self, factor: float):
              """Zoom in/out by factor (1.0 = no change).
      
              Make sure that we dont zoom out too far
              """
              self.zoom(factor)
              if axis_x := self.get_axes("horizontal"):
                  if axis_x[0].min() < self.min_x:
                      axis_x[0].setMin(self.min_x)
                  if axis_x[0].max() > self.max_x:
                      axis_x[0].setMax(self.max_x)
              if axis_y := self.get_axes("vertical"):
                  if axis_y[0].max() > self.max_y:
                      axis_y[0].setMax(self.max_y)
      
                  # always bottom-align when zooming for now. should perhaps become optional.
                  # if axis_y[0].min() < self.min_y:
                  axis_y[0].setMin(max(0, self.min_y))
      
          def get_chart_type(self) -> ChartTypeStr:
              return CHART_TYPES.inverse[self.chartType()]
      
          def get_margins(self) -> core.Margins:
              return core.Margins(self.margins())
      
          def get_plot_area(self) -> core.RectF:
              return core.RectF(self.plotArea())
      
          def get_locale(self) -> core.Locale:
              return core.Locale(self.locale())
      
          def get_theme(self) -> ThemeStr:
              return THEMES.inverse[self.theme()]
      
          def get_animation_options(self) -> list[AnimationOptionStr]:
              return ANIMATION_OPTIONS.get_list(self.animationOptions())
      
          def get_animation_easing_curve(self) -> core.EasingCurve:
              return core.EasingCurve(self.animationEasingCurve())
      

      adjust_style_to_palette()

      Adjusts the chart theme to current Palette.

      Checks if palette is dark-ish and applies an appropriate theme to the chart.

      Source code in prettyqt/charts/chart.py
      def adjust_style_to_palette(self):
          """Adjusts the chart theme to current Palette.
      
          Checks if palette is dark-ish and applies an appropriate theme to the chart.
          """
          pal = gui.GuiApplication.get_palette()
          style = "Dark" if pal.is_dark() else "Light"
          self.set_theme(style)
      

      apply_nice_numbers()

      Adjust both axis to display nice round numbers.

      Source code in prettyqt/charts/chart.py
      def apply_nice_numbers(self):
          """Adjust both axis to display nice round numbers."""
          for axis in self.get_axes():
              axis.applyNiceNumbers()
      

      get_axes(orientation: constants.OrientationStr | constants.Orientation | None = None, series: charts.QAbstractBarSeries | None = None) -> list[charts.QAbstractAxis]

      Get axes of chart.

      Parameters:

      Name Type Description Default
      orientation OrientationStr | Orientation | None

      Orientation of the axes that should get returned.

      None
      series QAbstractBarSeries | None

      Series to return axes for. Returns all axes if None.

      None
      Source code in prettyqt/charts/chart.py
      def get_axes(
          self,
          orientation: constants.OrientationStr | constants.Orientation | None = None,
          series: charts.QAbstractBarSeries | None = None,
      ) -> list[charts.QAbstractAxis]:
          """Get axes of chart.
      
          Arguments:
              orientation: Orientation of the axes that should get returned.
              series: Series to return axes for. Returns all axes if None.
          """
          if orientation is None:
              orientation = constants.HORIZONTAL | constants.VERTICAL
          return self.axes(constants.ORIENTATION.get_enum_value(orientation), series)
      

      set_legend_alignment(alignment: constants.SideStr | constants.AlignmentFlag)

      Set alignment of the chart legend.

      Source code in prettyqt/charts/chart.py
      def set_legend_alignment(
          self, alignment: constants.SideStr | constants.AlignmentFlag
      ):
          """Set alignment of the chart legend."""
          self.legend().setAlignment(constants.SIDES.get_enum_value(alignment))
      

      update_boundaries()

      Set new min/max values based on axis.

      Source code in prettyqt/charts/chart.py
      def update_boundaries(self):
          """Set new min/max values based on axis."""
          if axis_x := self.get_axes("horizontal"):
              self.max_x = axis_x[0].max()
              self.min_x = axis_x[0].min()
          if axis_y := self.get_axes("vertical"):
              self.max_y = axis_y[0].max()
              self.min_y = axis_y[0].min()
      

      zoom_by_factor(factor: float)

      Zoom in/out by factor (1.0 = no change).

      Make sure that we dont zoom out too far

      Source code in prettyqt/charts/chart.py
      def zoom_by_factor(self, factor: float):
          """Zoom in/out by factor (1.0 = no change).
      
          Make sure that we dont zoom out too far
          """
          self.zoom(factor)
          if axis_x := self.get_axes("horizontal"):
              if axis_x[0].min() < self.min_x:
                  axis_x[0].setMin(self.min_x)
              if axis_x[0].max() > self.max_x:
                  axis_x[0].setMax(self.max_x)
          if axis_y := self.get_axes("vertical"):
              if axis_y[0].max() > self.max_y:
                  axis_y[0].setMax(self.max_y)
      
              # always bottom-align when zooming for now. should perhaps become optional.
              # if axis_y[0].min() < self.min_y:
              axis_y[0].setMin(max(0, self.min_y))
      

      :fa-brands-github: Show source on GitHub