MCPcopy
hub / github.com/jmcnamara/XlsxWriter / add_chart

Method add_chart

xlsxwriter/workbook.py:252–314  ·  view source on GitHub ↗

Create a chart object. Args: options: The chart type and subtype options. Returns: Reference to a Chart object.

(self, options: Dict[str, Any])

Source from the content-addressed store, hash-verified

250 return xf_format
251
252 def add_chart(self, options: Dict[str, Any]) -> Optional[
253 Union[
254 ChartArea,
255 ChartBar,
256 ChartColumn,
257 ChartDoughnut,
258 ChartLine,
259 ChartPie,
260 ChartRadar,
261 ChartScatter,
262 ChartStock,
263 ]
264 ]:
265 """
266 Create a chart object.
267
268 Args:
269 options: The chart type and subtype options.
270
271 Returns:
272 Reference to a Chart object.
273
274 """
275
276 # Type must be specified so we can create the required chart instance.
277 chart_type = options.get("type")
278 if chart_type is None:
279 warn("Chart type must be defined in add_chart()")
280 return None
281
282 if chart_type == "area":
283 chart = ChartArea(options)
284 elif chart_type == "bar":
285 chart = ChartBar(options)
286 elif chart_type == "column":
287 chart = ChartColumn(options)
288 elif chart_type == "doughnut":
289 chart = ChartDoughnut()
290 elif chart_type == "line":
291 chart = ChartLine(options)
292 elif chart_type == "pie":
293 chart = ChartPie()
294 elif chart_type == "radar":
295 chart = ChartRadar(options)
296 elif chart_type == "scatter":
297 chart = ChartScatter(options)
298 elif chart_type == "stock":
299 chart = ChartStock()
300 else:
301 warn(f"Unknown chart type '{chart_type}' in add_chart()")
302 return None
303
304 # Set the embedded chart name if present.
305 if "name" in options:
306 chart.chart_name = options["name"]
307
308 chart.embedded = True
309 chart.date_1904 = self.date_1904

Callers 15

test_create_fileMethod · 0.95
test_create_fileMethod · 0.95
test_create_fileMethod · 0.95
test_create_fileMethod · 0.95
test_create_fileMethod · 0.95
test_create_fileMethod · 0.95
test_create_fileMethod · 0.95
test_unused_chartMethod · 0.95
test_create_fileMethod · 0.95
test_create_fileMethod · 0.95
test_create_fileMethod · 0.95
test_create_fileMethod · 0.95

Calls 10

ChartAreaClass · 0.85
ChartBarClass · 0.85
ChartColumnClass · 0.85
ChartDoughnutClass · 0.85
ChartLineClass · 0.85
ChartPieClass · 0.85
ChartRadarClass · 0.85
ChartScatterClass · 0.85
ChartStockClass · 0.85
getMethod · 0.80

Tested by 15

test_create_fileMethod · 0.76
test_create_fileMethod · 0.76
test_create_fileMethod · 0.76
test_create_fileMethod · 0.76
test_create_fileMethod · 0.76
test_create_fileMethod · 0.76
test_create_fileMethod · 0.76
test_unused_chartMethod · 0.76
test_create_fileMethod · 0.76
test_create_fileMethod · 0.76
test_create_fileMethod · 0.76
test_create_fileMethod · 0.76