import simplejson
from django.utils.html import escape


def render_highcharts_options(render_to, categories, series, title, x_axis_title, y_axis_title, series_name):
    """Accepts the parameters to render a chart and returns a JSON serialized Highcharts options object."""

    # Escape all the character strings to make them HTML safe.
    render_to = escape(render_to) if render_to else render_to
    title = escape(title) if title else title
    x_axis_title = escape(x_axis_title) if x_axis_title else x_axis_title
    y_axis_title = escape(y_axis_title) if y_axis_title else y_axis_title
    # Categories (dimensions) come from the use. Escape them too.
    categories = [escape(c) for c in categories]

    hco = {
        "chart": {
            "renderTo": render_to,
            "type": 'column'
        },
        "title": {
            "text": title
        },
        "xAxis": {
            "title": {
                "text": x_axis_title
            },
            "categories": categories
        },
        "yAxis": {
            "title": {
                "text": y_axis_title,
            }
        },
        "series": [{
            "name": series_name,
            "data": series,
        }]
    }

    return simplejson.dumps(hco, use_decimal=True)

@@ -364,16 +364,42 @@
 ender_to
+.encode('ascii', 'ignore')
 ) if ren
@@ -410,16 +410,17 @@
 to else 
+'
 render_t
@@ -420,16 +420,17 @@
 ender_to
+'
 %0A    tit
@@ -442,24 +442,50 @@
 escape(title
+.encode('ascii', 'ignore')
 ) if title e
@@ -488,21 +488,23 @@
 le else 
+'
 title
+'
 %0A    x_a
@@ -530,24 +530,50 @@
 x_axis_title
+.encode('ascii', 'ignore')
 ) if x_axis_
@@ -583,28 +583,24 @@
 le else 
-x_
+'x 
 axis
-_title
+'
 %0A    y_a
@@ -630,16 +630,42 @@
 is_title
+.encode('ascii', 'ignore')
 ) if y_a
@@ -679,28 +679,24 @@
 le else 
-y_
+'y 
 axis
-_title
+'
 %0A    # C
@@ -754,16 +754,16 @@
 em too.%0A
-
     cate
@@ -780,16 +780,42 @@
 escape(c
+.encode('ascii', 'ignore')
 ) for c 

Fix unicode error in series