I am trying to draw a timeline using pgfplots and dateplot:
This is inspired from How to create a multiline timeline but I would like to use real dates in this case.
Here is my example:
\documentclass{standalone}
\usepackage{pgfplots, pgfplotstable}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{dateplot}
\begin{document}
\pgfplotstableread[col sep=comma]{
condition, begin, end
Product A, 2020-02-17, 2020-07-12
Product B, 2020-04-02, 2020-05-28
Procuct C, 2020-08-12, 2021-01-02
Product D, 2020-11-01, 2021-03-02
}\ProductUsage
\centering
\begin{tikzpicture}
\begin{axis}[
date coordinates in=x,
xticklabel={\month -\year},
axis y line*=left,
axis x line=bottom,
xbar stacked,
ytick distance=1,
y=0.5cm,
width=\textwidth,
]
\addplot [draw=none, forget plot] table [x=begin, y expr=\coordindex]{\ProductUsage};
\addplot table [x=end, y expr=\coordindex]{\ProductUsage};
\end{axis}
\end{tikzpicture}
\end{document}
However this has a few issues:
- The timeline adds the "begin" time to the bar. It should just go from begin to end value.
- I would like to add the content for the "condition" column to the bar.
- bonus: It would be great to have month and years show op on different lines.
What I have tried so far:
- If i change
xbar stacked
byx bar
, every line starts at the earliest date. - If i try to get some calculation done like with
x expr=\thisrow{end}-\thisrow{begin}
, I get error messages due to the parsing of the date. - If I try to use
nodes near coords
for the label, I get the same date parsing error.