问题
Hi Guys I have a question or a request that I do not really know how to achieve.
I am using chart.js in my django app in order to retrieve data and render it in great graphs. I followed the tutorial and I managed to make it work but I would like my chart to add dataset dynamically. I would like to create a radar chart showing data from a team of x numbers. I created a test for a team of 2 people manually
HTML/Script:
labels_list = data.labels
info_data1 = data.data1
info_data1 = data.data2
var radar1 = {
labels: labels,
datasets: [{
label: "Team-member1",
fillColor: "rgba(255,255,255,0)",
strokeColor: "rgba(63,169,245,1)",
pointColor: "rgba(63,169,245,1)",
pointStrokeColor: "#fff",
data: info_data1
}, {
label: "Team-member2",
fillColor: "rgba(255,255,255,0)",
strokeColor: "rgba(102,45,145,1)",
pointColor: "rgba(102,45,145,1)",
pointStrokeColor: "#fff",
data: info_data2
}]
}
views.py:
def get(self, request, format=None, *args, **kwargs):
team_member_list = Project.objects.get(id=kwargs['pk']).team_id.members.all()
labels = ["Janv","Fev","March","April","May"]
data1 = [35,56,45,34,25]
data2 = [43,41,56,28,45]
data = {
"labels":labels,
"data1":data1,
"data2":data2
}
return Response(data)
How can I create the same kind of graph for X team members using dynamic data ??
ps: I just want to understand the logique.. so if someone can help me to render dynamically the dataset label (now "team member1/2") it would be great.. from there I will do the same to render the dynamic data linked to that team member
thx you vey much
来源:https://stackoverflow.com/questions/47575896/dynamic-chart-using-django-and-chart-js