novus/nvd3

Multibar chart y axis integer Value repeat

Opened this issue · 4 comments

Dear nvd3
In Multi bar chart Y axis repeat integer value how to fix this
set format Y axis
tickFormat: function (d) {
return d3.format(',.0f')(d);
}

below image

multibarchart

bgth commented

can you please share jsfiddle for the issue you are mentioning ?

$scope.options = {
chart: {
type: 'multiBarChart',
height: 240,
width: 400,
margin: {
top: 20,
right: 20,
bottom: 60,
left: 45
},
x: function (d) { return d.X; },
y: function (d) { return d.Y; },
clipEdge: false,
staggerLabels: true,
transitionDuration: 1000,
duration: 500,
useInteractiveGuideline: true,
tooltips: true,
tooltipContent: function (key, x, y, e, graph) {
return '

' + key + ': ' + y + '

';
},
stacked: true,
showControls: false,
wrapLabels: false,
clipVoronoi: false,
xAxis: {
axisLabel: 'Trunk',
staggerLabels: true,
axisLabelDistance: 1,
showMaxMin: true,

                tickFormat: function (d) {
                    return d3.format(',f')(d);
                }
            },
            yAxis: {
                axisLabel: 'Calls',
                //axisLabelDistance: 1,
                //tickFormat: function (d) {
                //    return d3.format(',.f')(d);
                //}
                tickFormat: function (d) {
                    return d3.format(',.0f')(d);
                },
                axisLabelDistance: 1
            }
        }
    };
bgth commented

Hi @viralchauhan .. not the code.. a live example on either jsfiddle.net or plnkr.co

I had this in BarCharts too.
On one hand you could say its a bug since integers are repeated.
On the other its regarding your definition of y-axis range vs. your y-values. So nvd3 is calculating ticks in range but is only allowed to show integers ( d3.format(',.0f') ) while you are using fractional parts as values.

As a solution to this you should specify more decimal digits e.g. for getting 0.1 ticks inbetween: (d3.format(',.1f') .
And don't forget to adjust the distance for your ticks and the label of yAxis.