using replace to produce javascript code, django

Posted by durdenk on Stack Overflow See other posts from Stack Overflow or by durdenk
Published on 2012-10-15T21:33:30Z Indexed on 2012/10/15 21:36 UTC
Read the original article Hit count: 174

Filed under:
|
|

I want to use highcharts with my django site but it requires a comlex javascript code such as below. So I wanted to get this script in my python code and replace apropriate portions then write it in my template, first question is, is this a dump way to do that for a person not knowing javascript. I can read it tough.

Second question is, Why I cant replace this string. Lets say this string is a variable like this.

lineChartsTemplate = """

...

...

"""

if I try and do

lineChartsTemplate .replace('dataCategory', dataCategory)

it basically suppossed to change dataCategory text with my dataCategory variable, but no such luck.

I need guidance here. thx.

$(function () { 
var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container',
        type: 'bar'
    },
    xAxis: {
        categories: dataCategory
    },
    yAxis: {   
    },
    legend: {
        layout: 'vertical',
        floating: true,
        backgroundColor: '#FFFFFF',
        align: 'right',
        verticalAlign: 'top',
        y: 60,
        x: -60
    },
    tooltip: {
        formatter: function() {
            return '<b>'+ this.series.name +'</b><br/>'+
                this.x +': '+ this.y;
        }
    },
    plotOptions: {
    },
    series: [{
        data: dataList ,      
        name : 'Satislar'}]
});
});

© Stack Overflow or respective owner

Related posts about django

Related posts about replace