question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom ticks of XAxis fixed

See original GitHub issue

Do you want to request a feature or report a bug?

It’s more of an implementation problem

What is the current behavior?

I tried <XAxis type="number" ticks={['09:00', '10:00', '11:00']} /> but both graph and the xaxis disappear

What is the expected behavior?

I want the XAxis to display fixed ticks like different hour in a day, and each coming new data will represent a seconds of it (much like of an stock chart)

Which versions of Recharts, and which browser / OS are affected by this issue? Did this work in previous versions of Recharts?

I am using "recharts": "^1.0.0-alpha.6"

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

28reactions
anze555commented, Dec 10, 2017

@TuanDSE62171 I read some other tickets and found a way to do this. The idea is to treat time as number (as you have specified in XAxis’s type) and to explicitly supply domain, ticks and tickFormatter. Working example:

import moment from 'moment';  // `yarn add moment`
const data = [
  {t: 1080001800, uv: 4000, pv: 2430, amt: [2400,2500]},
  {t: 1080005400, uv: 3000, pv: 1398, amt: [1210,1600]},
  {t: 1080009000, uv: 2000, pv: 2340, amt: [2290,2550]},
  {t: 1080012600, uv: 2780, pv: 2108, amt: [2000,2200]},
  {t: 1080016200, uv: 1890, pv: 2200, amt: [2181,2300]},
  {t: 1080019800, uv: 2390, pv: 2600, amt: [2500,2700]},
  {t: 1080023400, uv: 3490, pv: 2120, amt: [2100,2150]},
];

Then define XAxis like this:

<XAxis 
  dataKey="t" 
  type="number" 
  domain={[1080000000, 1080025200]}
  tickFormatter={(tick) => moment(tick * 1000).format('HH:mm')}
  ticks={[1080000000, 1080003600, 1080007200, 1080010800, 1080014400, 1080018000, 1080021600, 1080025200]}
/>

Using interval didn’t work for me - I got an empty axis whatever I did. Also, adding scale="time" led to empty axis.

Result: screenshot-2017-12-10 react app 1

As far as I’m concerned, my issue is solved. Hope it helps.

8reactions
Slebluuecommented, Aug 12, 2019

@dreamsparkx @veddermatic did you guys try setting the interval to 0?

http://recharts.org/en-US/api/XAxis#interval

Read more comments on GitHub >

github_iconTop Results From Across the Web

ggplot2 axis ticks : A guide to customize tick marks and labels
ggplot2 axis ticks : A guide to customize tick marks and labels · Data · Example of plots · Change the appearance of...
Read more >
Add custom tick marks to a SAS graph - The DO Loop
Specify custom labels for the ticks, including symbols such as π. You can accomplish these tasks by using options on the XAXIS and...
Read more >
Specify Axis Tick Values and Labels - MATLAB & Simulink
Customize the tick values and labels along an axis, such as editing the tick value placement or modifying the tick label text and...
Read more >
Chart.js - add custom, finite set of ticks at specific positions ...
I am trying to create a Chart.js line chart with a set number of ticks at fixed positions on the Y-axis. The Y-axis...
Read more >
Customizing Ticks | Python Data Science Handbook
The tick marks are no exception. Each axes has attributes xaxis and yaxis , which in turn have attributes that contain all the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found