-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
axis Tick for Date values #283
Comments
You can use axis |
I just saw that you're using an older version of the package, please upgrade to |
The source code for the time x scale demo is available here. |
@marcofranssen did you succeed in achieving what you wanted? |
@plouc still need to give it a shot in my repo. Recently been very busy in personal life. Will report back results asap. Thanks so far. |
hi @plouc ! First of all thanks for the awesome plotting library. I think I have a relatively simple question related to this discussion. I'm trying to just set an axis to use time, but not sure how to tell it what format my data is in (preferably I would pass it a JS Date object, or integer representing UNIX timestamp in ms). I saw this code from your example, but wasn't sure how to adapt it to UNIX timestamp or Date object? Thanks so much for the help!!!! |
@uclanate, you can set |
on the |
thanks @plouc ! next question, sorry if very basic. For axis labels, the code you used doesn't seem to work: |
which version are you using? |
Ah I'm an idiot. ok it works now!! (I was back on version 0.33). Thanks dude!!!! Great work here and thanks again for getting back so quickly :) |
@plouc first off, great library, thank you so much. Wondering if its possible to do hours rather than days? |
I figured it out... for anyone coming to look for something similar, I created an xScale that looks like this: then in axisBottom I set Which is perfectly what I was looking for. Hope this helps anyone else out there. |
Desperately trying to figure this out, maybe I'm reading the documentation wrong? Trying to get "ticksValues:5" working for ResponsiveBar but I'm getting every single date. This is my config:
my data looks like this:
And I'm on version "@nivo/bar": "^0.49.1", |
@raelmiu can we see more of the dataset? how many dates are there? In my solution, it still renders each 15 min increment, but setting the I might suggest jumping over to the discord channel where we can discuss a bit more, instead of here. |
As soon I add the following to my chart it crashes with following exception.
I get following exception:
I'm also on version 0.49.1. It would really help if there would be some working example. My current chart can be found over here. Would be great if someone can help me make this work. |
@marcofranssen perhaps you don't have a need for the time portion... by this I mean the H:M:S. I had the need in my code because my data was coming to me in that format. If you only need YYYY-MM-DD you can just use Y-m-d. And you would want to change the format from Or maybe you need to format using native as suggested to someone else. |
Maybe you can have a look at the storybook source |
@marcofranssen, are you sure the dates are all valid ones? |
I've tried to customize the xScale on a |
It's available on several component which use |
Any hints about my responsiveBar problem above? |
@raelmiu, it's difficult to help without having the code, if you can reproduce it on https://codesandbox.io for example, I can have a look, I understand it's for a client and you cannot use real data, but maybe you can use fake one. |
@plouc Here you go, faked Data and all: Still can't make this work. Tried all sorts of variants. |
Thank you @raelmiu, sorry, I missed that you're using a bar chart as the issue was initially about a line chart, the bar chart only support point scales (for x axis) and point scales don't support setting |
I found the issue. After I stripped the milliseconds from my datetime strings it works. So I think there is still a bug with regards to millis. But for now I'm good as I don't need milli precision. |
Thanks for the explanation! That makes sense. This is the documentation that confused me: http://nivo.rocks/guides/axes |
Is it possible to use date in x axis using stream chart ? If yes can anybody tell me the properties that I have to deal with or any sort of example available for it |
Thank you very much to all, this issue helped me so much with dates and tickValues, I managed to finish my chart |
any updates for scale time on bar chart @plouc ? |
What do you mean exactly? Where should I use this function? in case Im using {format: native} Update: Found the solution inside the storybook code:
|
In our case support for scale time in the bar chart is the only thing preventing us from adopting nivo generally. |
We ran into the milliseconds bug with ISO format and the solution was to add the // our data x format for time
x: 2020-07-31T16:50:00Z xScale={{
type: 'time',
format: '%Y-%m-%dT%H:%M:%SZ', // before we forgot the Z which broke the formatter
}} Without the |
I agree with others, scale time for the bar chart is a big pain point. |
Don't think this approach will work for everyone (maybe not even for myself once we're using real data) but, for now, I've fixed this issue by transforming the We need to use a unit-less transform so everything is relative to the SVG's viewBox. Adding that to the group with the tickValues after Nivo has updated its responsive styles should be enough to fix the alignment. handleResize () {
this.$nextTick(() => {
if (!process.client) { return this.handleResize() }
const colsGroup = document.querySelector('svg > g > g:first-of-type')
if (!colsGroup) { return this.handleResize() }
const val = colsGroup.querySelector('line').getAttribute('x1')
colsGroup.setAttribute('transform', `translate(-${val}, 0)`)
})
} I'm using this on Vue/Nuxt so you'll probably need to change some things to make it work in React-land but maybe someone will find this workaround useful. Does anyone know if this transform is the only thing missing in core to fix this issue or there's a bunch of more complex scenarios where this breaks differently? |
This fixed the issue I was having with milliseconds as well :-) |
I don't want to pile on by creating another issue but I just thought I'd add that the confusion around time axis config is why I'm not going to use nivo. I just want the ticks and tick formatting on my line chart to be dynamic like d3-axis automatically does by default, but I can't figure out how to do it. For example notice how the Victory time axis dynamically changes tick format precision based on the size of the domain. (You can mess around with the domain on this page to see it in action). https://formidable.com/open-source/victory/gallery/brush-and-zoom |
Bump would be good to have. |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Bump. |
bump. bit by the milliseconds issue |
I'm going to close this issue since it has been open quite a while and people are adding in what seems bugs and feature requests here and makes it hard to track. I'll leave with a couple of points:
|
I am facing this exact same issue, This is the x-scale I am trying to use xScale={{ |
@prachinerik, looking at the codesandbox, it seems like the format specifier is not expressed as expected, also when using time scales, the axis format has to be specified, could you please try the following?
|
I tried the suggested changes but am still getting the same error. |
@prachinerik, then you should adapt for this format:
|
Thanks for your reply. I tried with this format as well. It still does not
work.
This is the error I see:
nivo-scales.esm.js:112 Uncaught TypeError: Cannot read properties of null
(reading 'setMilliseconds')
at
***@***.***/scales/dist/nivo-scales.esm.js.precisionCutOffs
(nivo-scales.esm.js:112:1)
at nivo-scales.esm.js:128:1
at Array.forEach (<anonymous>)
at nivo-scales.esm.js:127:1
at nivo-scales.esm.js:146:1
at nivo-scales.esm.js:274:1
at Array.forEach (<anonymous>)
at nivo-scales.esm.js:273:1
at Array.forEach (<anonymous>)
at generateSeriesAxis (nivo-scales.esm.js:272:1)
…On Tue, Jul 26, 2022 at 5:40 PM Raphaël Benitte ***@***.***> wrote:
@prachinerik <https://github.com/prachinerik>, then you should adapt for
this format:
xScale={{
type: "time",
format: "%Y-%m-%d",
precision: "day"
}}
axisBottom={{
format: "%Y-%m-%d"
}}
—
Reply to this email directly, view it on GitHub
<#283 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALCUDMU2HEP6C3YATANJS3DVWCAP3ANCNFSM4FUBVQNA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Regards,
Prachi Nerikar.
|
@prachinerik could you please replicate the issue in codesandbox? I used this for the initial issue, and it works, so maybe something else is wrong, it's really hard to tell without having the full context (data + code). |
Hi @plouc , Unable to achieve it for line chart using need to convert large amout of dates into months in x axis , can you anyone help me with this. I've attached the codesandbox below |
Hi @saqlain1345, the date format does not match the format used in your data: |
Hey @plouc Can you please help me resolve the issue. import React, { useEffect, useState } from 'react'; const WaterLineChart = ({ data, timeframe }) => { const [formattedData, setFormattedData] = useState([]); useEffect(() => {
}, [data, timeframe]); const storageData = formattedData.filter(entry => entry.type === 'Storage'); const formatXAxis = (value) => {
}; const yAxisLegend = timeframe === 'today' ? "Volume (litres)" : "Average Volume (litres)"; const getTickValues = () => { return ( export default WaterLineChart; The above is my WaterLineChart.jsx . For timeframe= today I am getting error : Cannot read properties of null (reading 'setMilliseconds') Can anyone help me |
I'm trying to find a good example to get my xAxis ticks to be equally spread based on Date Time values.
I have been trying to accomplish this using http://nivo.rocks/guides/axes documentation. However so far no success. As my data collection is not always on the same interval my graph does not equally draw the visual representation but shows every data point with same distance.
Over here my chart code can be found. https://github.com/marcofranssen/gothermostat/blob/master/web/src/components/TemperaturesChart/TemperaturesChart.js
I would like the data to be shown where x axis represent equally spread during the start and end time.
Is there some documentation available to achieve this, or is this a missing feature?
The text was updated successfully, but these errors were encountered: