# Gantt Chart

**URL:** <https://discourse.julialang.org/t/gantt-chart/6988>\
**Category:** Visualization\
**Tags:** plotting, gadfly\
**Created:** [November 10, 2017, 6:33am UTC](https://discourse.julialang.org/t/gantt-chart/6988 "2017-11-10T06:33:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rahul\_Sharma](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@Rahul\_Sharma](https://discourse.julialang.org/u/Rahul_Sharma)\
**Post date:** [November 10, 2017, 6:33am UTC](https://discourse.julialang.org/t/gantt-chart/6988/1 "2017-11-10T06:33:43Z")

</div>

Hello,  
I want to draw a gnatt chart for a particular schedule using Gadfly. I have the start times of all products for a given machine and also its processing times.  
Can you please tell me how to do that?  
Thanks!

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [November 10, 2017, 8:33am UTC](https://discourse.julialang.org/t/gantt-chart/6988/2 "2017-11-10T08:33:29Z")

</div>

I like the idea of Gadfly plotting Gnat charts, but if you mean Gantt you could try:

> [@Plotting a gantt-chart like plot](https://discourse.julialang.org/t/plotting-a-gantt-chart-like-plot/2087):
>
> Hello, I would lie to plot a Gantt chart like the following starting from a dataframe, where each row containts (Task,Unit,InitialTime,Duration,Size) How would you approach this? thanks!

for an idea. But I don’t think there’s anything specifically for that.

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [November 11, 2017, 2:06am UTC](https://discourse.julialang.org/t/gantt-chart/6988/3 "2017-11-11T02:06:24Z")

</div>

```plaintext
using DataFrames, Gadfly

D1 = DataFrame(y = Int[1, 2, 3, 4],
    ylab=["Collect data", "Clean data", "Analyze data", "Write report"],
    x = Date.(["2017-04-01", "2018-04-01", "2018-06-01", "2019-04-01"]),
    xend = Date.(["2018-04-01", "2018-06-01", "2019-04-01", "2020-04-01"]),
    id = ["a","b","b","c"]
)
ylabdict = Dict(i=>D1[:ylab][i] for i in 1:4)

coord = Coord.cartesian(ymin=0.4, ymax=4.6)
p = plot(D1, coord,
    layer(x=:x, xend=:xend, y=:y, yend=:y, color=:id, Geom.segment, Theme(line_width=10mm)), 
    Scale.y_continuous(labels=i->get(ylabdict,i,"")),
    Guide.xlabel("Time"), Guide.ylabel(""),
    Theme(key_position=:none) 
)

```

![Gantt](https://global.discourse-cdn.com/julialang/original/3X/f/0/f086e0a4656216bdcc71c52085d7a27611c18934.png)

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [November 13, 2017, 9:24am UTC](https://discourse.julialang.org/t/gantt-chart/6988/4 "2017-11-13T09:24:26Z")

</div>

btw @Rahul_Sharma if the above solution works for you, then please use this action button on the post:

![discourse_solved](https://global.discourse-cdn.com/julialang/original/3X/f/f/ff4899d7d07e72b09c1ea8cfd3dda208b7992f6b.png)

---

<div class="post-metadata">

**Author:** ![Rahul\_Sharma](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@Rahul\_Sharma](https://discourse.julialang.org/u/Rahul_Sharma)\
**Post date:** [November 14, 2017, 8:27am UTC](https://discourse.julialang.org/t/gantt-chart/6988/5 "2017-11-14T08:27:34Z")

</div>

Can you please tell me what all packages are required for this? I tried running this code, but it threw errors.

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [November 14, 2017, 9:21am UTC](https://discourse.julialang.org/t/gantt-chart/6988/6 "2017-11-14T09:21:06Z")

</div>

I added the packages in the first line of code above. I’m using Julia 0.6.1. Please post any errors.

---

<div class="post-metadata">

**Author:** ![Rahul\_Sharma](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@Rahul\_Sharma](https://discourse.julialang.org/u/Rahul_Sharma)\
**Post date:** [November 14, 2017, 10:04am UTC](https://discourse.julialang.org/t/gantt-chart/6988/7 "2017-11-14T10:04:05Z")

</div>

it shows

```julia
LoadError: MethodError: no method matching size(::String)
Closest candidates are ---*bla bla*
while loading *address of my file* 
in expression starting from line * D1 = DataFrame(...*
in broadcast at base/broadcast.jl:230
in broadcast_t at base/broadcast.jl:213
in broadcast_shape at base/broadcast.jl:31
```

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [November 14, 2017, 10:13am UTC](https://discourse.julialang.org/t/gantt-chart/6988/8 "2017-11-14T10:13:51Z")

</div>

I can generate that error in Julia 0.5:

```nohighlight
> Date.("2017-04-01","2018-04-01")

ERROR: MethodError: no method matching size(::String)
Closest candidates are: *bla bla*
   ...
 in broadcast_shape(::String, ::String) at .\broadcast.jl:31
 in broadcast_t(::Type{T}, ::Type{Any}, ::String, ::Vararg{String,N}) at .\broadcast.jl:213
 in broadcast(::Type{T}, ::String, ::String) at .\broadcast.jl:230

```

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [November 14, 2017, 10:20am UTC](https://discourse.julialang.org/t/gantt-chart/6988/9 "2017-11-14T10:20:30Z")

</div>

Did you enclose the dates in a vector (note the square brackets)?:

```julia
Date.(["2017-04-01","2018-04-01"])

```

---

<div class="post-metadata">

**Author:** ![Rahul\_Sharma](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@Rahul\_Sharma](https://discourse.julialang.org/u/Rahul_Sharma)\
**Post date:** [November 14, 2017, 10:59am UTC](https://discourse.julialang.org/t/gantt-chart/6988/10 "2017-11-14T10:59:03Z")

</div>

Oh thanks. That was the issue it seems. Sorry for bothering you for such a silly mistake.
