# Combined grouped Bar and VProgress chart

A demo of the VProgress bar combined with a grouped Bar chart. It could be used to show different peoples stats over two years for example. Red is one year, yellow is the previous. The tooltip styling has been overridden using stylesheets and the positioning has been overridden by redefining the .positionTooltip() function on each vertical progress bar object (as well as defining a mousemove event on the canvas to update the tooltips position).

This goes in the documents header:

    <script src="RGraph.common.core.js"></script>
    <script src="RGraph.common.dynamic.js"></script>
    <script src="RGraph.common.tooltips.js"></script>
    <script src="RGraph.common.key.js"></script>
    <script src="RGraph.bar.js"></script>

    <style>
        .RGraph_tooltip img {
            display: none;
        }

        .RGraph_tooltip {
            box-shadow: none ! important;
            border: 2px solid blue ! important;
            background-color: white ! important;
            padding: 3px ! important;
            text-align: center;
            font-weight: bold;
            font-family: Verdana;
        }
    </style>

Put this where you want the chart to show up:

    <canvas id="cvs" width="600" height="250">
        [No canvas support]
    </canvas>

This is the code that generates the chart:

    <script>
        window.onload = function ()
        {
            var people = ['Rob','Luis','Kinga'];
            var bar = new RGraph.Bar({
                id: 'cvs',
                data: [[18,15,45],[21,23,41],[28,21,12],[21,15,38]],
                options: {
                    labels: ['January','February','March','April'],
                    hmargin: 20,
                    hmarginGrouped: 2,
                    highlightFill: 'red',
                    key: ['This year','Last year'],
                    keyColors: ['red','yellow'],
                    keyPosition: 'gutter',
                    keyPositionGutterBoxed: false,
                    textSize: 14,
                    colors: ['rgba(0,0,0,0)'],
                    noyaxis: true,
                    backgroundGridVlines: false,
                    backgroundGridBorder: false,
                    textAccessible: true
                }
            }).draw();

            function DrawBottomAxis (obj)
            {
                var context = bar.context;
                var x = bar.gutterLeft;
                var y = bar.canvas.height - bar.gutterBottom;
                var w = bar.canvas.width - bar.gutterLeft - bar.gutterRight
                var h = 0;
                context.strokeStyle = 'black';
                context.strokeRect(x, y, w, h);
            }

            /**
            * Now create the VProgress bars
            */
            for (var i=0,j=0; i<bar.coords.length; ++i,++j) {

                if (i % 3 == 0) {
                    j = 0;
                }

                var coords = bar.coords[i];

                var vp = new RGraph.VProgress({
                    id: 'cvs',
                    min: 0,
                    max: 100,
                    value: [25,75],
                    options: {
                        gutterLeft: coords[0],
                        gutterTop: coords[1],
                        gutterRight: bar.canvas.width - (coords[0] + coords[2]),
                        gutterBottom: bar.gutterBottom,
                        labelsCount: 0,
                        tickmarks: false,
                        colors: ['yellow', 'rgba(255,0,0,0.5)'],
                        tooltips: [people[j],people[j]],
                        tooltipsEvent: 'mousemove',
                        tooltipsEffect: 'none',
                        strokestyle: 'rgba(0,0,0,0)',
                        textAccessible: true
                    }
                }).on('draw',  DrawBottomAxis)
                  .draw();

                /**
                * Override the function that positions the tooltip and place to the right of
                * the mouse pointer.
                */
                vp.positionTooltip = function (obj, x, y, tooltip, idx)
                {
                    tooltip.style.top = (y  - tooltip.offsetHeight - 3) + 'px';
                    tooltip.style.left = (x - 3) + 'px';
                }

                vp.canvas.onmousemove = function (e)
                {
                    var tooltip = RGraph.Registry.Get('chart.tooltip');

                    if (tooltip) {
                        tooltip.style.top = (e.pageY  - tooltip.offsetHeight - 3) + 'px';
                        tooltip.style.left = (e.pageX + 3) + 'px';
                    }
                }

                vp.canvas.onmouseout = function (e)
                {
                    RGraph.hideTooltip();
                    RGraph.redraw();
                }
            }
        };
    </script>