Gantt Chart

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!

1 Like

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

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

2 Likes
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

7 Likes

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

discourse_solved

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

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

it shows

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

I can generate that error in Julia 0.5:

> 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

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

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

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