Adding New Group Methods, JavaScript Programming Example of Adding New Group Methods

JavaScript Adding New Group Methods

If you want to add your own operation and new group methods in Pivot Chart, use the programming example below. Don't miss the chance to use free coding samples by Webix to accelerate the process of web development.

JS Code

var chart = webix.ui({
  id:"pivot",
  view:"pivot-chart",
  height:300,
  structure:{
    groupBy: "year",
    values: [{name:"balance", operation:"sum", color: "#eed236"},{name:"balance", operation:"average", color: "#36abee"}],
    filters:[{name:"name", type:"select"}]
  },
  groupMethods:{
    average: function(template, data){
      data = data || this;
      var summ = 0;
      for (var i = 0; i < data.length; i++)
        summ+= template(data[i])*1;
      return data.length?summ/data.length:0;
    }
  },
  data:pivot_data
});