Add a data series to a chart. Args: options: A dictionary of chart series options. Returns: Nothing.
(self, options: Optional[Dict[str, Any]] = None)
| 110 | self.fill = {} |
| 111 | |
| 112 | def add_series(self, options: Optional[Dict[str, Any]] = None) -> None: |
| 113 | """ |
| 114 | Add a data series to a chart. |
| 115 | |
| 116 | Args: |
| 117 | options: A dictionary of chart series options. |
| 118 | |
| 119 | Returns: |
| 120 | Nothing. |
| 121 | |
| 122 | """ |
| 123 | # Add a series and it's properties to a chart. |
| 124 | if options is None: |
| 125 | options = {} |
| 126 | |
| 127 | # Check that the required input has been specified. |
| 128 | if "values" not in options: |
| 129 | warn("Must specify 'values' in add_series()") |
| 130 | return |
| 131 | |
| 132 | if self.requires_category and "categories" not in options: |
| 133 | warn("Must specify 'categories' in add_series() for this chart type") |
| 134 | return |
| 135 | |
| 136 | if len(self.series) == 255: |
| 137 | warn( |
| 138 | "The maximum number of series that can be added to an " |
| 139 | "Excel Chart is 255" |
| 140 | ) |
| 141 | return |
| 142 | |
| 143 | # Convert list into a formula string. |
| 144 | values = self._list_to_formula(options.get("values")) |
| 145 | categories = self._list_to_formula(options.get("categories")) |
| 146 | |
| 147 | # Switch name and name_formula parameters if required. |
| 148 | name, name_formula = self._process_names( |
| 149 | options.get("name"), options.get("name_formula") |
| 150 | ) |
| 151 | |
| 152 | # Get an id for the data equivalent to the range formula. |
| 153 | cat_id = self._get_data_id(categories, options.get("categories_data")) |
| 154 | val_id = self._get_data_id(values, options.get("values_data")) |
| 155 | name_id = self._get_data_id(name_formula, options.get("name_data")) |
| 156 | |
| 157 | # Set the line properties for the series. |
| 158 | line = Shape._get_line_properties(options) |
| 159 | |
| 160 | # Set the fill properties for the series. |
| 161 | fill = Shape._get_fill_properties(options.get("fill")) |
| 162 | |
| 163 | # Set the pattern fill properties for the series. |
| 164 | pattern = Shape._get_pattern_properties(options.get("pattern")) |
| 165 | |
| 166 | # Set the gradient fill properties for the series. |
| 167 | gradient = Shape._get_gradient_properties(options.get("gradient")) |
| 168 | |
| 169 | # Pattern fill overrides solid fill. |