Building chart using charjs in Django

Viewed 13

I need to create a chart with chartjs with displaying month wise count on current year in a line chart. The data should be retrieved from the model named "invoice" and the feild name is "Invoice_date".

Note: Invoice_date is an DateFeild().

in views.py

def home(request):
    if request.user.is_authenticated:
        customers = User.objects.filter(groups__name='Customer').count()
        totalinvoice = invoice.objects.all().count()
        supplier = User.objects.filter(is_staff=True).count()

        # chart
        labels = ["Jan","Feb","Mar","Apr","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
        data = [12,14,19,25,28,80,23,35,46,78,45,23] // This data's should be retrieved dynamically

        return render(request, 'home.html', {
            'totalinvoices':totalinvoice,
            'customers':customers,
            'supplier':supplier,
            "labels":json.dumps(labels),
            "data":json.dumps(data),
        })
    else:
        return redirect("login")

Please someone help me in figuring out.

0 Answers
Related