javascript - How to set the value of the Y-AXIS of Graphs with nvd3.js -
im trying set value of y-axis using nvd3.js: in y-axis: [0,0.1,0.2,0.3,...,0.9,1]
what want display 0 , 1. try chart.yrange([0,1])but doesn't work me. have 1 idea how realise that.
this have:
this code:
line: function () { var self = this, dim_x = this.pivot.rows.groupby.length, dim_y = this.pivot.cols.groupby.length; var rows = this.pivot.get_rows_with_depth(dim_x), labels = _.pluck(rows, 'title'); var data = _.map(this.pivot.get_cols_leaves(), function (col) { var values = _.map(rows, function (row, index) { return {x: index, y: self.pivot.get_values(row.id,col.id)[0] || 0}; }); var title = _.map(col.path, function (p) { return p || _t('undefined'); }).join('/'); if (dim_y === 0) { title = self.pivot.measures[0].string; } return {values: values, key: title}; }); nv.addgraph(function () { // var chart = nv.models.linewithfocuschart() var chart = nv.models.linechart() .x(function (d,u) { return u; }); /// max , min of chart var i; var max,min; for(i=0;i<data[0].values.length;i++){ //alert("y:"+data[0].values[i].y); if (i==0) { max=data[0].values[i].y;min=data[0].values[i].y; } if (max<data[0].values[i].y) { max=data[0].values[i].y; } if (min>data[0].values[i].y) { min=data[0].values[i].y; } } chart.xaxis.tickformat(function (d,u) {return labels[d];}); if ((min == 0) &(max==1)){ //here check when max 1 , min 0 } //alert("ticks:"+chart.yaxis.ticks()) d3.select(self.svg) .attr('width', self.width) .attr('height', self.height) .datum(data) .call(chart); return chart; }); }
call tickvalues([0,1]) on y-axis chart object.


Comments
Post a Comment