I'm trying to use google chart in my Django project, the google chart required a format like
['label1', 'label2', 'label3', new Date(Y, m, d), new Date(Y, m, d), null, 100, null], it's
like a list, so I'm trying to keep things simple first, I only replaced the date with template tags and leave other fields as default. The template tage works well alone in P element and output result as "2014, 10, 12".
I would really appreciate it if someone can have a look, cheers.
views.py
def visualisation(request, project_id):
project = Project.objects.get(id=project_id)
counts_data = Todo.objects.aggregate(
to_do_count=Count('id', filter=Q(status='to_do')),
in_progress_count=Count('id', filter=Q(status='in_progress')),
done_count=Count('id', filter=Q(status='done'))
)
todos = project.todo_set.order_by('-project_code')
return render(request, 'todo_lists/progress.html', {"counts_data":counts_data,'team':team,'todos':todos})
HTML
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Task ID');
data.addColumn('string', 'Task Name');
data.addColumn('string', 'Resource');
data.addColumn('date', 'Start Date');
data.addColumn('date', 'End Date');
data.addColumn('number', 'Duration');
data.addColumn('number', 'Percent Complete');
data.addColumn('string', 'Dependencies');
data.addRows([
{% for todo in todos %}
['Introduction', 'Introduction Project', 'Introduction',
new Date({{ todo.start_date|date:"Y,m,d"}}), new Date({{ todo.due_date|date:"Y,m,d"}}), null, 50, null]{% if not forloop.last %},{% endif %}{% endfor %}
]);