Elm-charts formatting of dates

Hi @hansv! Thank you for your kind words :blush: I didn’t realize that there wasn’t a good example for editing time label formatting- thanks for letting me know! I’ll add one at my earliest convenience.

For basic formatting you can use the format attribute on the x or y labels in question (like in this example). It will give you the timestamp (in float, so you will likely need to round it) which you can format as you’d like. I like using the ryannhg/date-format package for this!

However, if you need more advanced formatting, where you’d like use some higher level information than just the timestamp (e.g. info relative to other labels such as whether this label just changed month or year etc.) you can do that too, just a little more tricky. I made you a little ellie with an example which I hope is helpful! The gist is that you need to use the generate API to produce Time's which holds all the info available for each timestamp. You can then create exactly the labels you’d like! This is not as elegant for midlevel needs as I’d like it to be right now, but I hope I’ll find a nice way to improve it in the future. In the meanwhile, thank you for your patience!

Let me know if you have any further questions!

5 Likes