Returns html for a chart

def get(self, slug, xdata, ydatasets, label, opts, style, ctype):
        """
        Returns html for a chart
        """
        xdataset = self._format_list(xdata)
        width = "100%"
        height = "300px"
        if opts is not None:
            if "width" in opts:
                width = str(opts["width"])
            if "height" in opts:
                height = str(opts["height"])
        stylestr = '<style>#container_' + slug + \
            ' { width:' + width + ' !important; height:' + \
            height + ' !important}</style>\n'
        html = stylestr
        html += '<div id="container_' + slug + \
            '"><canvas id="canvas_' + slug + '"></canvas></div>\n'
        html += '<script>\n'
        html += 'var data = {\n'
        html += 'labels: ' + xdataset + ',\n'
        html += 'datasets:[\n'
        colors = None
        if "color" in style:
            colors = style["color"]
        i = 0
        for dataset in ydatasets:
            name = dataset["name"]
            data = dataset["data"]
            html += self._get_dataset(data, name, colors)
            if i < len(ydatasets) - 1:
                html += ","
            i += 1
        html += ']\n'
        html += '}\n'

        html += 'window.onload = function() {'
        html += 'var ctx = document.getElementById("canvas_' + \
                slug + '").getContext("2d");'
        html += 'window.myChart = new Chart(ctx, {'
        html += 'type: "' + ctype + '",'
        html += 'data: data,'
        html += 'options: {'
        html += 'spanGaps: false,'
        html += 'responsive: true,'
        html += 'maintainAspectRatio: false,'
        if "legend" in opts:
            html += 'legend: {'
            html += 'position: "' + opts["legend"] + '",'
            html += '},'
        else:
            html += 'legend: {'
            html += 'display: false,'
            html += '},'
        if "title" in opts:
            html += 'title: {'
            html += 'display: true,'
            html += 'text: "' + opts["title"] + '"'
            html += '}'
        html += '}'
        html += '});'
        html += '};'
        html += '</script>\n'
        return html