How to create Gantt charts
You may use TimelinePlot
with the PlotStyle
option.
For a project with schedule
of start date and duration for a few teams.
SeedRandom[23032]
schedule =
Partition[
Transpose@{
RandomSample[
DateRange[DateObject@{2018, 2, 1}, DateObject@{2018, 2, 28}, "Day"], 12],
RandomInteger[{2, 7}, 12]
},
3]
Then
TimelinePlot[Map[Interval@{First@#, DatePlus @@ #} &, schedule, {2}],
PlotStyle -> Thickness@[email protected],
PlotLegends -> SwatchLegend[Automatic, StringTemplate@"Team `1`" /@ Range@4]]
Additional formatting can be added by referring to the documentation.
Hope this helps.
Using the data schedule
from @Edmund's answer, (1) wrapping each date range with Labeled
and (2) modifying FrameTicks
to add additional labels:
ranges = Map[Interval@{First@#, DatePlus @@ #} &, schedule, {2}];
boxlabels = Style[ToUpperCase@#, 12] & /@ RandomWord["Noun", Length[Join @@ schedule]];
labeling = Thread[Join @@ ranges -> boxlabels];
labeledData = Labeled[##, Before]& @@@ # & /@ (Transpose[{#, # /. labeling}] & /@ ranges);
grouplabels = StringTemplate@"GROUP `1`" /@ Range[Length@schedule];
groupsizes = Length /@ ranges;
ticklabels = StringTemplate@"PROJECT `1`" /@ Range[Length[Join @@ schedule]];
spacings = 4;
tlp = TimelinePlot[labeledData, ImageSize -> 700, LabelStyle -> 14,
Spacings -> spacings, Frame -> True,
PlotMarkers -> {Automatic, 1}, AspectRatio -> 1/GoldenRatio,
PlotRangePadding -> {{Scaled[.25], Automatic}, {Scaled[.02], Scaled[.05]}},
PlotLayout -> "Stacked",
PlotStyle -> Directive[Thickness[.03], CapForm[None]],
PlotLegends -> SwatchLegend[grouplabels],
GridLines -> {{AbsoluteTime@{2018, 2, 15, 8}}, None},
Method -> {"GridLinesInFront" -> True}] /. Point[__] :> Nothing ;
Show[tlp, Options[tlp[[1]], FrameTicks] /.
{None, None} -> {MapIndexed[{ spacings #2[[1]], #} &, ticklabels],
MapIndexed[{spacings (Accumulate[groupsizes][[#2[[1]]]] -
Floor[groupsizes[[#2[[1]]]]/2]), #} &, grouplabels]}]