Insert an chart with its top-left corner in a worksheet cell. Args: row: The cell row (zero indexed). col: The cell column (zero indexed). chart: Chart object. options: Position and scale of the chart. Returns:
(
self, row: int, col: int, chart: Chart, options: Optional[Dict[str, Any]] = None
)
| 1698 | |
| 1699 | @convert_cell_args |
| 1700 | def insert_chart( |
| 1701 | self, row: int, col: int, chart: Chart, options: Optional[Dict[str, Any]] = None |
| 1702 | ) -> Literal[0, -1, -2]: |
| 1703 | """ |
| 1704 | Insert an chart with its top-left corner in a worksheet cell. |
| 1705 | |
| 1706 | Args: |
| 1707 | row: The cell row (zero indexed). |
| 1708 | col: The cell column (zero indexed). |
| 1709 | chart: Chart object. |
| 1710 | options: Position and scale of the chart. |
| 1711 | |
| 1712 | Returns: |
| 1713 | 0: Success. |
| 1714 | -1: Row or column is out of worksheet bounds. |
| 1715 | |
| 1716 | """ |
| 1717 | # Check insert (row, col) without storing. |
| 1718 | if self._check_dimensions(row, col, True, True): |
| 1719 | warn(f"Cannot insert chart at ({row}, {col}).") |
| 1720 | return -1 |
| 1721 | |
| 1722 | if options is None: |
| 1723 | options = {} |
| 1724 | |
| 1725 | # Ensure a chart isn't inserted more than once. |
| 1726 | if chart.already_inserted or chart.combined and chart.combined.already_inserted: |
| 1727 | warn("Chart cannot be inserted in a worksheet more than once.") |
| 1728 | return -2 |
| 1729 | |
| 1730 | chart.already_inserted = True |
| 1731 | |
| 1732 | if chart.combined: |
| 1733 | chart.combined.already_inserted = True |
| 1734 | |
| 1735 | x_offset = options.get("x_offset", 0) |
| 1736 | y_offset = options.get("y_offset", 0) |
| 1737 | x_scale = options.get("x_scale", 1) |
| 1738 | y_scale = options.get("y_scale", 1) |
| 1739 | anchor = options.get("object_position", 1) |
| 1740 | description = options.get("description", None) |
| 1741 | decorative = options.get("decorative", False) |
| 1742 | |
| 1743 | # Allow Chart to override the scale and offset. |
| 1744 | if chart.x_scale != 1: |
| 1745 | x_scale = chart.x_scale |
| 1746 | |
| 1747 | if chart.y_scale != 1: |
| 1748 | y_scale = chart.y_scale |
| 1749 | |
| 1750 | if chart.x_offset: |
| 1751 | x_offset = chart.x_offset |
| 1752 | |
| 1753 | if chart.y_offset: |
| 1754 | y_offset = chart.y_offset |
| 1755 | |
| 1756 | self.charts.append( |
| 1757 | [ |