0

hello everyone i want to create a bar chart using my database value in django i am create a model that is

class statictab(models.Model):
    def indiantime():
        date = now() + timedelta(minutes = 330)
        return date.date()
    user = models.ForeignKey(usertab,on_delete = True)
    date = models.DateField(default=indiantime)
    click = models.IntegerField(default=0)

i have save last 10 days click of every user in my database so i have fillter user last 10 days data like this

this is views.py

def createchart(request):
    if request.session.has_key('user_id'):
        pastdate = timezone.now() - timedelta(days=9) + timedelta(minutes=330)
        nowdate = timezone.now() + timedelta(minutes=330)
        staticdata = statictab.objects.filter(date__range=[pastdate.date() , nowdate.date() ],user_id=request.session['user_id'])
        d={"data" : staticdata}
        return return render(request,"html/chart.html",d)

in my d dictionary last 10 days data are present so i want to create a bar chart using chart.js so how i cant do this in my tamplate

my template chart.html

<html>
<head>

#all script and css are linked

</head>


<body>
<div id = "mychart">   

</div>

<script>
window.onload = function () {

    var chart = new CanvasJS.Chart("mychart", {
    animationEnabled: true,
    title:{
        text: "Last 10 Days View"
    },
    axisX:{
        // valueFormatString: "DD MMM"
    },
    axisY: {
        title: "Number of Click",
    },
    data: [{
        type: "line",
        xValueFormatString: "DD MMM",
        color: "#F08080",
        dataPoints: [
            // { x: new Date(2017, 0, 7), y: 734 },
            // { x: new Date(2017, 0, 8), y: 963 },
            // { x: new Date(2017, 0, 9), y: 847 },
            // { x: new Date(2017, 0, 10), y: 853 }
            # how i give my database value on this place for create chart using for loop or other methord

        ]
    }]
});
</script>


</body>
</html>
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.