'Draw a Bar Chart
- used by the Survey module'

def survey_bar(self, title, data, labels, legendLabels):

    barColourList = ['#F2D7A0', '#7B77A8', '#69889A', '#9D7B34']
    barColourListExt = [(242, 215, 160), (123, 118, 168), (105, 136, 154), (157, 123, 52)]
    fig = self.fig
    if (not fig):
        return 'Matplotlib    not    installed'
    from numpy import arange
    if (not isinstance(data[0], list)):
        dataList = [data]
    else:
        dataList = data
    legendColCnt = 3
    cnt = len(labels)
    dcnt = len(dataList)
    lcnt = 0
    if (legendLabels != None):
        lcnt = (((len(legendLabels) + legendColCnt) - 1) / legendColCnt)
    width = (0.9 / dcnt)
    offset = 0
    gap = (0.1 / dcnt)
    bcnt = 0
    bars = []
    height = max(0.2, (0.85 - (0.04 * lcnt)))
    rect = [0.08, 0.08, 0.9, height]
    ax = fig.add_axes(rect)
    for data in dataList:
        left = arange(offset, (cnt + offset))
        if (bcnt < 3):
            colour = barColourList[bcnt]
        else:
            colour = []
            colourpart = barColourListExt[(bcnt % 4)]
            divisor = (256.0 - ((32 * bcnt) / 4))
            if (divisor < 0.0):
                divisor = (divisor * (-1))
            for part in colourpart:
                calc = (part / divisor)
                while (calc > 1.0):
                    calc -= 1
                colour.append(calc)
        plot = ax.bar(left, data, width=width, color=colour)
        bars.append(plot[0])
        bcnt += 1
        offset += (width + gap)
    left = arange(cnt)
    lblAdjust = ((1.0 - gap) * 0.5)
    if (cnt <= 3):
        angle = 0
    elif (cnt <= 10):
        angle = (-10)
    elif (cnt <= 20):
        angle = (-30)
    else:
        angle = (-45)
    ax.set_xticks((left + lblAdjust))
    try:
        ax.set_xticklabels(labels, rotation=angle)
        ax.tick_params(labelsize=self.width)
    except AttributeError:
        newlabels = []
        for label in labels:
            if (len(label) > 12):
                label = (label[0:10] + '...')
            newlabels.append(label)
        ax.set_xticklabels(newlabels)
    ax.set_title(title)
    if (legendLabels != None):
        fig.legend(bars, legendLabels, 'upper    left', mode='expand', ncol=legendColCnt, prop={'size': 10})
