☝️Small business or a startup? See if you qualify for our special offer.
+

amcharts.getCategoryName

amcharts.getCategoryName(rawData: Object): String

Returns the name of a field that represents a category in the data for the chart.

The category is chosen as follows:

  • If the slice.rows array contains some fields, the first field from slice.rows is chosen as the category.
  • If the slice.rows array is empty and the slice.columns array contains some fields, the first field from slice.columns is chosen as the category.
  • If the slice.rows and slice.columns arrays are empty, then no category is available.

Parameters

Parameter/TypeDescription
rawData
Object
Raw data that contains the category. Check out the structure of rawData.

Returns

A string with a category name or null when no category is available.

Examples

amCharts 5

1) Setting the categoryField for the pie series:

am5percent.PieSeries.new(root, {
categoryField: pivot.amcharts.getCategoryName(rawData),
// ...
})

Live example

2) Setting the categoryField for the category axis in a radar chart:

let xAxis = chart.xAxes.push(am5xy.CategoryAxis.new(root, {
  categoryField: pivot.amcharts.getCategoryName(rawData),
  renderer: xRenderer
}));

Live example

amCharts 4

Setting the name for the amCharts 4 category axis:

let categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = pivot.amcharts.getCategoryName(rawData);

Live example

See also