Adjusting your charts interactively - Gantt chart

Share RGraph:   

The Gantt chart can be adjusted by dragging the bars left or right, or the events can be resized if you place the cursor at the right edge of the event. To get the details of the bar being dragged you can use the onadjust or onadjustend events, and in that you can look at the RGraph registry - RGraph.Registry.get('chart.adjusting.gantt') The returned array consists of:

When adjusting is complete the obj.data array is updated. So you can use the numerical index that you find in the registry (as above) with the obj.data array to get up-to-date event information.

Note: The Gantt chart uses console.log() to send notifications. Press CTRL+SHIFT+J in Chrome to see the console, or use Firebug in Firefox. Other browsers will vary.

[No canvas support] Event ID: Event start: Event duration:
<script>
    window.onload = function (e)
    {
        gantt_events = [
            [31, 28, null, 'Richard'],
            [0, 120, null, 'Bob'],
            [84, 16, null, 'Fred'],
            [35, 45, null, 'Charles'],
            [0, 35, null, 'Kev'],
        ];

        var gantt = new RGraph.Gantt({
            id: 'cvs',
            data: gantt_events,
            options: {
                xmax: 120,
                defaultcolor: '#0c0',
                labels: ['January', 'February', 'March', 'April'],
                borders: false,
                adjustable: true,
                textAccessible: true
            }
        }).draw().on('onadjustend',function (obj)
        {
            var idx = RGraph.Registry.get('chart.adjusting.gantt')[0];
        
        }).on('onadjust',function (obj)
        {
            var events = obj.data;
            var conf   = RGraph.Registry.get('chart.adjusting.gantt');
            
            if (conf) {
                var idx = conf['index'];
                document.getElementById("eventID").value       = idx;
                document.getElementById("eventStart").value    = events[idx][0];
                document.getElementById("eventDuration").value = events[idx][1];
                
                console.log(
                    'Event ID: ' + idx +
                    'Event start: ' + events[idx][0] +
                    ' Event duration: ' + events[idx][1]
                );
            }
        });
    }
</script>

Comments

Add a new comment...