[Answer]-Using replace to produce javascript code, django

1👍

I think the best you can do is use django template system to achieve the kind of replacing you need.

If you put in your template something like this.

$(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 : 'Satışlar'}]
});
});

Then you could substitute dataCategory with something like

return render_to_response(
    "template_with_embedded_js",
    {'dataCategory': dataCategory},
    RequestContext(request))
👤esauro

Leave a comment