如何在Django上选择我的图表js图上的时间?
我试着选择只在我的图表上显示什么,但我不知道它叫什么。请帮忙 我的看法是这样的如何在Django上选择我的图表js图上的时间?,django,charts,Django,Charts,我试着选择只在我的图表上显示什么,但我不知道它叫什么。请帮忙 我的看法是这样的 class ResView(LoginRequiredMixin, ListView): model = Rainfall template_name = 'home.html' context_object_name = 'res' paginate_by = 8 queryset = Rainfall.objects.all().order_by('-id') d
class ResView(LoginRequiredMixin, ListView):
model = Rainfall
template_name = 'home.html'
context_object_name = 'res'
paginate_by = 8
queryset = Rainfall.objects.all().order_by('-id')
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["qs"] = Rainfall.objects.all()
return context
<script>
(function () {
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [{% for i in qs %}'{{i.timestamp}}',{% endfor %}],
datasets: [{
label: 'Rainfall Graph',
data: [{% for i in qs %}'{{i.amount}}',{% endfor %}],
lineTension: 0,
backgroundColor: 'transparent',
borderColor: '#c9c5c5',
borderWidth: 2,
pointRadius: 1,
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: false
}
}]
},
legend: {
display: false
}
}
})
}());
我的图表是这样的
class ResView(LoginRequiredMixin, ListView):
model = Rainfall
template_name = 'home.html'
context_object_name = 'res'
paginate_by = 8
queryset = Rainfall.objects.all().order_by('-id')
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["qs"] = Rainfall.objects.all()
return context
<script>
(function () {
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [{% for i in qs %}'{{i.timestamp}}',{% endfor %}],
datasets: [{
label: 'Rainfall Graph',
data: [{% for i in qs %}'{{i.amount}}',{% endfor %}],
lineTension: 0,
backgroundColor: 'transparent',
borderColor: '#c9c5c5',
borderWidth: 2,
pointRadius: 1,
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: false
}
}]
},
legend: {
display: false
}
}
})
}());
(功能(){
var ctx=document.getElementById('myChart').getContext('2d');
var myChart=新图表(ctx{
键入:“行”,
数据:{
标签:[{%fori-in-qs%}'{{i.timestamp}}',{%endfor%}],
数据集:[{
标签:'降雨图',
数据:[{%fori在qs%}{{i.amount}}',{%endfor%}],
线张力:0,
背景色:“透明”,
边框颜色:“#C9C5C5C5”,
边界宽度:2,
点半径:1,
}]
},
选项:{
比例:{
雅克斯:[{
滴答声:{
贝吉纳泽罗:错
}
}]
},
图例:{
显示:假
}
}
})
}());
现在我想选择要在图表上显示的内容。像这样的下拉列表。我有一个选择
<select>
<option value="hour">Hour</option>
<option value="day">Day</option>
<option value="month">Month</option>
</select>
时辰
白天
月