[Tex/LaTex] How to change the color of ganttbar

pgfgantttikz-pgf

I want to set the color of intervals

  • 14:00-15:00 to red
  • 19:00-20:30 to green
  • 20:30-21:30 to yellow

How to change it?

MWE

\documentclass[border=12pt]{standalone}
\usepackage{pgfgantt}

\ganttset{group/.append style={transparent},
milestone/.append style={red},
progress label node anchor/.append style={text=red}}

\begin{document}
    \begin{ganttchart}[
     y unit title=0.5cm,
     y unit chart=0.7cm,
     vgrid,hgrid,
     title height=1,
     title label font=\bfseries\footnotesize,
     bar/.style={fill=blue},
     bar height=0.7,
     group right shift=0,
     group top shift=0.7,
     group height=.3,
     group peaks width={0.5},
     inline]{1}{24}
    \gantttitle{7}{2}
    \gantttitle{8}{2}
    \gantttitle{10}{2}
    \gantttitle{11}{2}
    \gantttitle{12}{2}
    \gantttitle{13}{2}
    \gantttitle{14}{2} 
    \gantttitle{15}{2}
    \gantttitle{19}{2}
    \gantttitle{20}{2}
    \gantttitle{21}{2} 
    \gantttitle{22}{2}\\
    \ganttgroup[inline=false]{Monday}{0}{0}
    \ganttbar[]{}{14}{15}% red
    \ganttbar[]{}{18}{20}% green
    \ganttbar[]{}{21}{22}\\% yellow
\end{ganttchart}
\end{document}

enter image description here

Best Answer

You could use [bar/.append style={fill=red}] like this:

    \ganttbar[bar/.append style={fill=red}]{}{14}{15}% red
    \ganttbar[bar/.append style={fill=green}]{}{18}{20}% green
    \ganttbar[bar/.append style={fill=yellow}]{}{21}{22}\\% yellow

enter image description here

MWE:

\documentclass[border=12pt]{standalone}
\usepackage{pgfgantt}

\ganttset{group/.append style={transparent},
milestone/.append style={red},
progress label node anchor/.append style={text=red}}

\begin{document}
    \begin{ganttchart}[
     y unit title=0.5cm,
     y unit chart=0.7cm,
     vgrid,hgrid,
     title height=1,
     title label font=\bfseries\footnotesize,
     bar/.style={fill=blue},
     bar height=0.7,
     group right shift=0,
     group top shift=0.7,
     group height=.3,
     group peaks width={0.5},
     inline]{1}{24}
    \gantttitle{7}{2}
    \gantttitle{8}{2}
    \gantttitle{10}{2}
    \gantttitle{11}{2}
    \gantttitle{12}{2}
    \gantttitle{13}{2}
    \gantttitle{14}{2} 
    \gantttitle{15}{2}
    \gantttitle{19}{2}
    \gantttitle{20}{2}
    \gantttitle{21}{2} 
    \gantttitle{22}{2}\\
    \ganttgroup[inline=false]{Monday}{0}{0}
    \ganttbar[bar/.append style={fill=red}]{}{14}{15}% red
    \ganttbar[bar/.append style={fill=green}]{}{18}{20}% green
    \ganttbar[bar/.append style={fill=yellow}]{}{21}{22}\\% yellow
\end{ganttchart}
\end{document}
Related Question