Highcharts percentage of total for simple bar chart

前端 未结 4 861
野的像风
野的像风 2020-11-30 07:12

I have a simple 1-series bar chart where each bar has a nominal value. I can plot this fine with the data labels and axis representing the value for each bar but I\'d like t

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 07:52

    try this.percentage

    It's pretty well documented in the highcharts API as well.

    http://api.highcharts.com/highcharts#plotOptions.series.dataLabels.formatter

    EDIT

    Since you'd need it for non-stacked series, you'd need to get the total before generating the graph... The function below adds up your values into one variable which you can use in your formatter function later.

    function arrayTotal(arr)
    {
      var total = 0;
      for (var i = 0, value; value = arr[i]; i++)
      {
        total += value;
      }
      return total;
    }
    

提交回复
热议问题