MCPcopy Create free account
hub / github.com/scanny/python-pptx / CategoryChartData

Class CategoryChartData

src/pptx/chart/data.py:255–339  ·  view source on GitHub ↗

Accumulates data specifying the categories and series values for a chart and acts as a proxy for the chart data table that will be written to an Excel worksheet. Used as a parameter in :meth:`shapes.add_chart` and :meth:`Chart.replace_data`. This object is suitable for use with

Source from the content-addressed store, hash-verified

253
254
255class CategoryChartData(_BaseChartData):
256 """
257 Accumulates data specifying the categories and series values for a chart
258 and acts as a proxy for the chart data table that will be written to an
259 Excel worksheet. Used as a parameter in :meth:`shapes.add_chart` and
260 :meth:`Chart.replace_data`.
261
262 This object is suitable for use with category charts, i.e. all those
263 having a discrete set of label values (categories) as the range of their
264 independent variable (X-axis) values. Unlike the ChartData types for
265 charts supporting a continuous range of independent variable values (such
266 as XyChartData), CategoryChartData has a single collection of category
267 (X) values and each data point in its series specifies only the Y value.
268 The corresponding X value is inferred by its position in the sequence.
269 """
270
271 def add_category(self, label):
272 """
273 Return a newly created |data.Category| object having *label* and
274 appended to the end of the category collection for this chart.
275 *label* can be a string, a number, a datetime.date, or
276 datetime.datetime object. All category labels in a chart must be the
277 same type. All category labels in a chart having multi-level
278 categories must be strings.
279 """
280 return self.categories.add_category(label)
281
282 def add_series(self, name, values=(), number_format=None):
283 """
284 Add a series to this data set entitled *name* and having the data
285 points specified by *values*, an iterable of numeric values.
286 *number_format* specifies how the series values will be displayed,
287 and may be a string, e.g. '#,##0' corresponding to an Excel number
288 format.
289 """
290 series_data = CategorySeriesData(self, name, number_format)
291 self.append(series_data)
292 for value in values:
293 series_data.add_data_point(value)
294 return series_data
295
296 @property
297 def categories(self):
298 """|data.Categories| object providing access to category-object hierarchy.
299
300 Assigning an iterable of category labels (strings, numbers, or dates) replaces
301 the |data.Categories| object with a new one containing a category for each label
302 in the sequence.
303
304 Creating a chart from chart data having date categories will cause the chart to
305 have a |DateAxis| for its category axis.
306 """
307 if not getattr(self, "_categories", False):
308 self._categories = Categories()
309 return self._categories
310
311 @categories.setter
312 def categories(self, category_labels):

Calls

no outgoing calls

Tested by 10

rewrite_fixtureMethod · 0.72
make_category_chart_dataFunction · 0.72
add_cat_fixtureMethod · 0.72
add_ser_fixtureMethod · 0.72
categories_fixtureMethod · 0.72
values_ref_fixtureMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…