<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_chart(self):
 """Write color palette to Altair Chart. """

        encoding, properties = {}, {}

        if self.orientation == "horizontal":
            # Set the axis
            encoding["x"] = alt.X(
                "hex",
                axis=None,
                scale=alt.Scale(zero=False, padding=0)
            )

            # Set the rectangle size.
            properties["width"] = len(self.df)*self.square_size
            properties["height"] = self.square_size

        elif self.orientation == "vertical":
            # Set the axis
            encoding["y"] = alt.Y(
                "hex",
                axis=None,
                scale=alt.Scale(zero=False, padding=0)
            )

            # Set the rectangle size.
            properties["height"] = len(self.df)*self.square_size
            properties["width"] = self.square_size

        # Build a chart.
        tooltip = list(self.df.columns)
        chart = alt.Chart(self.df).mark_rect().encode(
            color=alt.Color("hex", legend=None, scale=alt.Scale(range=self.colors)),
            tooltip=tooltip,
            **encoding
        ).properties(
            **properties
        )
        return chart