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.

Axis scaleTime Interval

See original GitHub issue

https://github.com/d3/d3-scale#time_ticks

According to the d3 docs an interval may be supplied to the ticks. I have used <AxisBottom numTicks={timeYear} /> which seems to work as expected but fails props validation:

Warning: Failed prop type: Invalid prop `numTicks` of type `function` supplied to `Axis`, expected `number`.

Relevant https://github.com/hshoff/vx/blob/master/packages/vx-axis/src/axis/Axis.js#L82

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
esetnikcommented, Jun 19, 2018

Hi @hshoff thanks for your help. I don’t fully understand how to use tickValues for the bottom axis in conjunction with scaleTime. The problem is that if the data is only a few points (where one point is each year) then the axis automatically switches to month ticks. I’d like to use https://github.com/d3/d3-time#_interval to constrain the axis ticks to be just the years. You can see what I mean in the example where i’ve constrained the data to one point per year for only two years. Do I need to iterate the data and manually come up with an array of tickValues to pass to <Axis />? Is it possible that tickValues could take a function which reduces the input data to a sensible array of tick values? Then you’d be able to do something like <Axis tickValues={timeYear} />.

0reactions
Ricardinh0commented, Jan 29, 2020

I agree with @esetnik. Be nice to not use tickValues as an alternative when d3 scaleTime.ticks() can accept either a number or a TimeInterval.

https://github.com/d3/d3-scale#time_ticks

Noob question, but can the type be simply updated to a union of number | TimeInterval?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Axis scaleTime Interval · Issue #310 · airbnb/visx - GitHub
The problem is that if the data is only a few points (where one point is each year) then the axis automatically switches...
Read more >
d3.scaleTime - Observable
The default range is the usual interval [0,1]. range = Array(2) [0, 1]. Time scales are commonly used for charts where one axis...
Read more >
Offset x-axis ticks with scaleTime - Stack Overflow
Save this question. Show activity on this post. I'm trying to figure out how I can offset the x-axis ticks, as shown in...
Read more >
Working with D3 Time Series Axes - Developer.com
In today's article, we'll learn how to use the scaleTime() function to present time series data on the x axis of a chart....
Read more >
Working With Dates - Using D3.js
Once we have the axis function, we call it to draw the axis. var xScale = d3.scaleTime() .domain(domain) .range([25, 555]); var xAxis =...
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