Question

I'm doing a project with Django and I'm using nvd3 charts to render some data. The version I'm using is:

<script src="http://nvd3.org/lib/d3.v2.js" type="text/javascript\"></script>
<script src="http://nvd3.org/nv.d3.js" type="text/javascript\"></script>

I don't have any troubles with the charts but the axis key. This is the part where I initialize the data list:

data = [{
            'color': 'green',
                'values': [],
                'key': 'whatever',
                'yAxis': '1'
        }, ];

If I initialize the data like this I don't get any error and the chart is rendered succesfully, but If I'm using a word with accent like "whatéver" in the template the axis key is render as "whatéver". My first option was adding unicode to the string something like:

data = [{
            'color': 'green',
                'values': [],
                'key': u'whatéver',
                'yAxis': '1'
        }, ];

But when I add the u to the string I get this error on browser console:

Uncaught SyntaxError: Unexpected string

and the chart is not rendered

Any suggestions ? I've checked nvd3 documentation but couldn't find any related with this.

Edit: I've tried to use HTML encoding for the char "é" like:

data = [{
            'color': 'green',
                'values': [],
                'key': u'what&egrave;ver',
                'yAxis': '1'
        }, ];

Didn't work out

Was it helpful?

Solution

Found one solution by passing the variable to the template encoded for JavaScript.

I want to render whatéver so I pass to the template what\351ver

I'm not sure if this is the only solution or there is another one better than this

I didn't choose my answer as correct in case that somebody knows another option better than this one

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top