TimeLinePlot tooltip shows Day rather than Year
From InputForm[TimelinePlot[DateObject[{2019}, "Year"] -> "Foo"]]
one can see, that MMA uses Day
as granularity for DateObject
s. So, one possible solution is to change these objects to the needed form:
TimelinePlot[DateObject[{2019}, "Year"] -> "Foo"] /.
DateObject[a__, "Day", b__] :> DateObject[a, "Year", b]
Another possibility is using custom LabelingFunction
:
TimelinePlot[DateObject[{2019}, "Year"] -> "Foo",
LabelingFunction -> (DateObject[FromAbsoluteTime@First@#, "Year"] &)]
Update: For input data with mixed date granularity:
dates = {DateObject[{2019, 11}, "Month"] -> "Month",
DateObject[{2019}, "Year"] -> "Year",
DateObject[{2019, 5, 15}, "Week"] -> "Week",
DateObject[{2020, 10}, "Year"] -> "Year2",
DateObject[{2019, 10}, "Quarter"] -> "Quarter"};
TimelinePlot[Tooltip[#, #] -> #2 & @@@ Sort[dates]]
Original answer:
An alternative work-around is to wrap DateObject
s with Tooltip
:
TimelinePlot[Tooltip[#, #] & @ DateObject[{2019}, "Year"] -> "Foo"]
TimelinePlot[Tooltip[#, #]& @ DateObject[{2019, 11}, "Month"] -> "Foo"]