Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the decimal values in integers in Discrete Bar chart

i m using the Discrete Bar chart (NVD3 Library) to display chart in my site. while showing graph everything is fine, but my problem is that how to change the decimal values to integers. values that are showing in y-axis displaying integer values. although which array i used to display values having integer values. js code which i used are below

     nv.addGraph(function() {  
     var chart = nv.models.discreteBarChart()
    .x(function(d) { return d.label })
    .y(function(d) { return d.value })
    .staggerLabels(true)
    .tooltips(false)
    .showValues(true)
    .transitionDuration(250);
    chart.xAxis.axisLabel("<?php echo $configureGrid['x_axis']['legend']; ?>");
    chart.yAxis.axisLabel("<?php echo $configureGrid['y_axis']['legend']; ?>");
    d3.select('#issue_by_time svg')
    .datum(historicalBarChart)
    .call(chart);
    nv.utils.windowResize(chart.update);
    return chart;
    });
    });
like image 362
Moaz Ateeq Avatar asked Dec 10 '13 16:12

Moaz Ateeq


2 Answers

use this,

chart.yAxis.tickFormat(d3.format(',f'));

to convert decimals value into integer for y-axis

chart.xAxis.tickFormat(d3.format(',f'));

to convert decimals value into integer for x-axis

chart.valueFormat(d3.format('d'));

to convert decimals value into integer, that takes input by graph

like image 107
Moaz Ateeq Avatar answered Oct 05 '22 22:10

Moaz Ateeq


chart.valueFormat(d3.format('d')); this shows the exact values as in the data table (it may be integer or float)

to show the exact vale on showValue option you can use .valueFormat(d3.format('.0'));

like image 30
user3172663 Avatar answered Oct 06 '22 00:10

user3172663