Chandni
You just need to extend the proper widget class using include, like:
var GraphWidget = require('web.GraphWidget');
GraphWidget.include({
display_bar: function () {
// prepare data for bar chart
var data, values,
measure = this.fields[this.measure].string;
// zero groupbys
if (this.groupbys.length === 0) {
data = [{
values: [{
x: measure,
y: this.data[0].value}],
key: measure
}];
}
// one groupby
if (this.groupbys.length === 1) {
values = this.data.map(function (datapt) {
return {x: datapt.labels, y: datapt.value};
});
data = [
{
values: values,
key: measure,
}
];
}
if (this.groupbys.length > 1) {
var xlabels = [],
series = [],
label, serie, value;
values = {};
for (var i = 0; i < this.data.length; i++) {
label = this.data[i].labels[0];
serie = this.data[i].labels[1];
value = this.data[i].value;
if ((!xlabels.length) || (xlabels[xlabels.length-1] !== label)) {
xlabels.push(label);
}
series.push(this.data[i].labels[1]);
if (!(serie in values)) {values[serie] = {};}
values[serie][label] = this.data[i].value;
}
series = _.uniq(series);
data = [];
var current_serie, j;
for (i = 0; i < series.length; i++) {
current_serie = {values: [], key: series[i]};
for (j = 0; j < xlabels.length; j++) {
current_serie.values.push({
x: xlabels[j],
y: values[series[i]][xlabels[j]] || 0,
});
}
data.push(current_serie);
}
}
var svg = d3.select(this.$el[0]).append('svg');
svg.datum(data);
svg.transition().duration(0);
var chart = nv.models.multiBarChart();
var maxVal = _.max(values, function(v) {return v.y})
chart.options({
margin: {left: 12 * String(maxVal && maxVal.y || 0).length},
delay: 250,
transition: 10,
showLegend: _.size(data) <= MAX_LEGEND_LENGTH,
showXAxis: true,
showYAxis: true,
rightAlignYAxis: false,
stacked: this.stacked,
reduceXTicks: false,
rotateLabels: 40,
showControls: (this.groupbys.length > 1)
});
chart.yAxis.tickFormat(function(d) { return formats.format_value(d, { type : 'float' });});
chart(svg);
this.to_remove = chart.update;
nv.utils.onWindowResize(chart.update);
}
});
Hope this help you