Sepp

Special Character degree

Recommended Posts

Hello Team,

i have the problem in python Django does when i take the special Special Character degree it will not display on browser

This is my django code  < views.py>

def weather_chart(request):
    
    tester = sensoren.objects.filter(sensorname='Aussen').order_by('-id')[:1]
    
    dataSource1 = {}
    
    dataSource1['chart'] = {
                  "caption":"Temperatur Alfdorf",
                  "subCaption":"Aktueller Tagesverlauf °",
                  "yAxisName":"Temperatur",
                  "yAxisNameFontSize":"14",
                  "captionOnTop":"1",
                  "labeldisplay": "ROTATE",
                  "slantlabels": "1",
                  "labelStep":"4",
                  "drawAnchors":"0",
                  "showValues":"0",
                  "theme":"fint"
               }
    dataSource1['data'] =[]
    
    for key in sensoren.objects.filter(sensorname='Aussen', \
                                       messdatum__range=[datetime.combine(date.today(), time.min), \
                                                         datetime.combine(date.today(), time.max)]):
        data = {}
        data['label'] = datetime.time(key.messdatum).strftime("%H:%M")
        data['value'] = key.temperatur
        dataSource1['data'].append(data)               
   
    # Create an object for the column2d chart using the FusionCharts class constructor
    column2d = FusionCharts("line", "ex1" , "450", "300", "Temperchart", "json", dataSource1) 

this is the html code

<div id="Temperchart"> 
     <script type="text/javascript">
         FusionCharts.ready(function () {
             new FusionCharts({"width": "450", "renderAt": "Temperchart", "dataFormat": "json", "type": "line", "height": "300", "id": "ex1", "dataSource": {"data": [{"label": "00:00", "value": "-8.5"}, {"label": "00:15", "value": "-8.9"}, {"label": "00:30", "value": "-8.9"}, {"label": "00:45", "value": "-9.2"}, {"label": "01:00", "value": "-9.1"}, {"label": "01:15", "value": "-9.0"}, {"label": "01:30", "value": "-9.5"}, {"label": "01:45", "value": "-9.9"}, {"label": "02:00", "value": "-9.9"}, {"label": "02:15", "value": "-10.3"}, {"label": "02:30", "value": "-10.4"}, {"label": "02:45", "value": "-10.1"}, {"label": "03:00", "value": "-10.1"}, {"label": "03:15", "value": "-10.2"}, {"label": "03:30", "value": "-10.0"}, {"label": "03:45", "value": "-9.6"}, {"label": "04:00", "value": "-9.9"}, {"label": "04:15", "value": "-9.9"}, {"label": "04:30", "value": "-10.0"}, {"label": "04:45", "value": "-10.0"}, {"label": "05:00", "value": "-9.8"}, {"label": "05:15", "value": "-9.6"}, {"label": "05:30", "value": "-9.5"}, {"label": "05:45", "value": "-9.8"}, {"label": "06:00", "value": "-9.8"}, {"label": "06:15", "value": "-9.8"}, {"label": "06:30", "value": "-9.7"}, {"label": "06:45", "value": "-9.9"}, {"label": "07:00", "value": "-10.2"}, {"label": "07:15", "value": "-10.2"}, {"label": "07:30", "value": "-10.2"}, {"label": "07:45", "value": "-10.1"}, {"label": "08:00", "value": "-9.4"}, {"label": "08:15", "value": "-9.4"}, {"label": "08:30", "value": "-8.9"}, {"label": "08:45", "value": "-8.9"}, {"label": "09:00", "value": "-8.2"}, {"label": "09:15", "value": "-7.2"}, {"label": "09:30", "value": "-6.2"}, {"label": "09:45", "value": "-5.2"}, {"label": "10:00", "value": "-4.5"}, {"label": "10:15", "value": "-3.9"}, {"label": "10:30", "value": "-3.6"}, {"label": "10:45", "value": "-3.5"}, {"label": "11:00", "value": "-3.0"}, {"label": "11:15", "value": "-3.0"}, {"label": "11:30", "value": "-2.5"}, {"label": "11:45", "value": "-2.1"}, {"label": "12:00", "value": "-1.7"}, {"label": "12:15", "value": "-1.5"}, {"label": "12:30", "value": "-1.2"}, {"label": "12:45", "value": "-1.0"}, {"label": "13:00", "value": "-1.0"}, {"label": "13:15", "value": "-0.9"}, {"label": "13:30", "value": "-0.8"}, {"label": "13:45", "value": "-0.8"}, {"label": "14:00", "value": "-0.8"}, {"label": "14:15", "value": "-0.9"}, {"label": "14:30", "value": "-0.6"}, {"label": "14:45", "value": "-0.7"}, {"label": "15:00", "value": "-0.8"}, {"label": "15:15", "value": "-0.9"}, {"label": "15:30", "value": "-1.0"}, {"label": "15:45", "value": "-1.2"}, {"label": "16:00", "value": "-1.3"}, {"label": "16:15", "value": "-1.6"}, {"label": "16:30", "value": "-2.0"}, {"label": "16:45", "value": "-2.0"}, {"label": "17:00", "value": "-2.5"}, {"label": "17:15", "value": "-3.2"}, {"label": "17:30", "value": "-3.8"}, {"label": "17:45", "value": "-4.4"}, {"label": "18:00", "value": "-5.1"}, {"label": "18:15", "value": "-5.9"}, {"label": "18:30", "value": "-6.5"}, {"label": "18:45", "value": "-6.8"}, {"label": "19:00", "value": "-6.7"}, {"label": "19:15", "value": "-6.6"}, {"label": "19:30", "value": "-6.6"}, {"label": "19:45", "value": "-6.5"}, {"label": "20:00", "value": "-6.3"}, {"label": "20:15", "value": "-6.5"}], "chart": {"drawAnchors": "0", "yAxisNameFontSize": "14", "yAxisName": "Temperatur", "caption": "Temperatur Alfdorf", "labelStep": "4", "slantlabels": "1", "labeldisplay": "ROTATE", "captionOnTop": "1", "theme": "fint", "showValues": "0", "subCaption": "Aktueller Tagesverlauf u00b0"}}});
         });
     </script>
     <script type="text/javascript">
         FusionCharts.ready(function () {
             FusionCharts("ex1").render();
         });

and the screenshot is at the attachment.

has anybody a solution?

Depp

chart.png

Share this post


Link to post
Share on other sites

Hello,

sorry I'm to stupid. I try many things about this problem

"subCaption": u"\N{DEGREE SIGN}"

or

u = u"\N{DEGREE SIGN}"
    dataSource1['chart'] = {
                  "caption":"Temperatur Alfdorf",
                  "subCaption": u.encode("utf8"),

but always the same problem

do you have any hint for me

Michael

Share this post


Link to post
Share on other sites

Hi,

Apologies for the delayed response. Since all the chart attributes are provided as a string the Python compiler is changing the degree symbol to its corresponding Unicode, therefore as a workaround, you can apply the degree symbol using javascript from your view page and apply this method when the chart has been initialized using FusionCharts API events, to know more check this sample - https://www.dropbox.com/s/ovb7nm0li5g6buv/fc_column2d.zip?dl=0

To know about initialized events check here - https://www.fusioncharts.com/dev/api/fusioncharts/fusioncharts-events#initializedstatic-event-7

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now