Introduction
A basic implementation of a Gantt Chart using D3.js.
Adapted from https://github.com/dk8996/Gantt-Chart
Getting Started
Data
Create a array of all your data.
var eventList = [
{"startDate":new Date("Sun Dec 09 01:00:00 EST 2012"),"endDate":new Date("Sun Dec 09 01:45:00 EST 2012"),"taskName":"Main Stage","status":"4","toolTipHTML":"Band 1"},
{"startDate":new Date("Sun Dec 09 02:00:00 EST 2012"),"endDate":new Date("Sun Dec 09 02:45:00 EST 2012"),"taskName":"Main Stage","status":"4","toolTipHTML":"Band 2"},
{"startDate":new Date("Sun Dec 09 03:00:00 EST 2012"),"endDate":new Date("Sun Dec 09 03:45:00 EST 2012"),"taskName":"Main Stage","status":"4","toolTipHTML":"Band 3"},
Style
List out the css classes that you will be using for the event tiles
eventStyleClassList:[
"blue-bar",
"purple-bar",
"red-bar",
"green-bar",
"orange-bar"
]
.blue-bar {
fill: #33b5e5;
}
.blue-bar:hover {
fill: #9ED2E6;
}
.yellow-bar {
fill: #fffe35;
}
.yellow-bar:hover {
fill: #fffeb3;
}
Event Types
Create a array of event types, they will be display on they y-axis in the order given to the array.
eventTypes:[ "Main Stage", "Left Stage", "Underground Stage" ]
Create a Simple Gantt-Chart
Create a simple Gantt-Chart
var gantt =
var ganttConfig = {
eventSettings: {
eventList: eventList,
eventTypes:[ "Main Stage", "Left Stage", "Underground Stage" ],
eventStyleClassList:[
"blue-bar",
"purple-bar",
"red-bar",
"green-bar",
"orange-bar"],
enableToolTips: true
},
sizing: {
location:'GanttChart',
margin:{
top : 60,
right : 40,
bottom : 20,
left : 120
},
height:"400",
width:"700"
},
timeDomainSettings: {
zoomLevels:["5:sec","15:sec","1:min","5:min","15:min","1:hr","3:hr","6:hr","1:day"],
timeDomainStart:d3.time.day.offset(new Date(),-3),
timeDomainEnd: d3.time.hour.offset(new Date(),+3),
startingTimeFormat:"%H:%M",
startingTimeDomainString:"1day",
startingZoomLevel:8,
timeDomainMode: "fixed"
}
};
var GanttChart = d3.gantt(ganttConfig);
Dependencies & Building
Relies on the fantastic D3 visualization library to do lots of the heavy lifting for stacking and rendering to SVG.
License
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.