All documentation
  • API Reference for older versions
  • amcharts.getNumberOfMeasures

    amcharts.getNumberOfMeasures(rawData: Object)

    Returns the total number of available measures in the slice.

    This method can be used to create a chart with multiple series (e.g., the stacked column chart). 

    Parameters

    Parameter/TypeDescription
    rawData
    Object
    Raw data containing the measures to count (check out the structure of rawData in getData()).

    Returns

    Returns a number representing the quantity of measures in the slice.

    Examples

    amCharts 5

    Using amcharts.getNumberOfMeasures() to create a stacked column chart:

    for (let s = 0; s < pivot.amcharts.getNumberOfMeasures(rawData); s++) {
      let series = chart.series.push(am5xy.ColumnSeries.new(root, {
        name: pivot.amcharts.getMeasureNameByIndex(rawData, s),
        xAxis: xAxis,
        yAxis: yAxis,
        stacked: true,
        valueYField: pivot.amcharts.getMeasureNameByIndex(rawData, s),
        categoryXField: pivot.amcharts.getCategoryName(rawData),
      }));
    
      series.data.setAll(data);
    }

    See the full code on JSFiddle.

    amCharts 4

    Using amcharts.getNumberOfMeasures() to create a stacked column chart:

    for (let s = 0; s < pivot.amcharts.getNumberOfMeasures(rawData); s++) {
      let series = chart.series.push(new am4charts.ColumnSeries());
      series.dataFields.categoryX = pivot.amcharts.getCategoryName(rawData);
      series.dataFields.valueY = pivot.amcharts.getMeasureNameByIndex(rawData, s);
      series.name = pivot.amcharts.getMeasureNameByIndex(rawData, s);
      series.stacked = true;
    }

    See the full code on JSFiddle.

    See also

    amcharts.getData
    amcharts.getCategoryName
    amcharts.getMeasureNameByIndex
    amcharts.getNumberFormatPattern