6

I've just converted my project from using react vis over to recharts. I'm currently looking into why the ticks aren't showing as expected. There are 96 datapoints that should be showing up and the cartesian grid shows them, but no tick labels appear other than the few at weird times not aligned to the datapoints I provide. (The tick marks should be at a 30 minute interval.)

Is there a way to have the ticks show up just where I specify them in the data?

This is what I currently have (I thought "interval" was supposed to make all the ticks appear). I have the time specified as milliseconds and then format them, which seems to work for the most part.

<LineChart data={datapoints}>
    <XAxis dataKey="x"
           domain = {['auto', 'auto']}
           name = 'Time'
           tickFormatter = {(unixTime) => moment(unixTime).format('HH:mm')}
           interval={0}
           type = 'number'/>
    <YAxis />
    <CartesianGrid/>
    <Tooltip/>
    <Legend/>
    {this.props.yLines.map(lineKey => {
        return <Line dot={false} type="monotone" dataKey={lineKey} isAnimationActive={false}/>
    })}
</LineChart>

And this is what is showing up: Times aren't at intervals

Vs what I would expect (all intervals showing) enter image description here

Update: I have since added tickCount={96} (like I had with react-vis) but the times are still at weird increments. Like 6:33, 8:20, etc. instead of 30 minute increments.

Any help would be appreciated!

CustardBun
  • 3,457
  • 8
  • 39
  • 65

2 Answers2

10

You can use interval={0} in your XAxis. It will show all tick

Tai Do
  • 117
  • 1
  • 8
2

Use scale="time" in your XAxis.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Spam Magnet
  • 86
  • 1
  • 8