1

I am trying to create a line chart.

Specifying ticks: 7 for a lineChart, but only 6 ticks are showing up.

This is the data and option values

this.options = {
      chart: {
        type: 'lineChart',
        showYAxis:false,
        showLabels:true,
        showLegend:false,
        reduceXTicks: false,
        margin : {
          top: 20,
          right: 20,
          bottom: 40,
          left:20
        },
        x: function(d){ return d.x; },
        y: function(d){ return d.y; },
        xAxis: {
          tickFormat:function(d) { 
            return d3.time.format('%b %d')(new Date(d)); 
          },
          ticks:7
        }
      }
    };

    this.data=[
      {
        values: [    
        {x: new Date('2015-03-23'),y:10},
        {x:new Date('2015-03-24'),y:20},
        {x:new Date('2015-03-25'),y:5},
        {x: new Date('2015-03-26'),y:10},
        {x:new Date('2015-03-27'),y:15},
        {x:new Date('2015-03-28'),y:20},
        {x:new Date('2015-03-29'),y:40}
        ],
        key: 'Cosine Wave',
        color: '#d0021c',
        area:true
      }
    ]

See the plunker -https://plnkr.co/edit/7zg62ezs730i40U0GTHy?p=preview

Any help would be appreciated.

Abhay Srivastav
  • 754
  • 6
  • 16

1 Answers1

0

One workaround I found is that you set the ticks with tickValues.

var xAxis = d3.axisBottom(x).tickValues([1, 2, 3, 5, 8, 13, 21]);

https://github.com/d3/d3-axis/blob/master/README.md#axis_tickValues

Or then you can pass the tick values to the directive:

<nvd3-line-chart  
  data="graphData"   
  xAxisTickValues="xAxisTicks"  
</nvd3-line-chart> 

and then in scope:

$scope.xAxisTicks = function(){  
    return [new Date('2013-12-31'), new Date('2014-1-1'), new Date('2014-1-2')];  
  } 

Also notice this "tick arguments will still be passed to the scale’s tickFormat function if a tick format is not also set"

Shnigi
  • 972
  • 9
  • 19