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:

\usepackage{pgfplots, pgfplotstable}


\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
            date coordinates in=x,
            xticklabel={\month -\year},
            axis y line*=left,
            axis x line=bottom,
            xbar stacked,
            ytick distance=1,
        \addplot [draw=none, forget plot] table [x=begin, y expr=\coordindex]{\ProductUsage};
        \addplot table [x=end, y expr=\coordindex]{\ProductUsage};


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 by x 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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.