template.html
<script src="http://code.highcharts.com/highcharts.js">
</script>
<script >
$(document).ready(function() {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'line'
},
title: {
text: 'Power Consumption Vs Generator Consumption'
},
xAxis: {
categories: [{{month_number|join:"','" }}]
},
yAxis: {
title: {
text: 'Fruit eaten'
}
},
// series: [{
// name: 'Truepower Consumed',
// data: [1, 0, 4]},
// {
// name: 'Generator Consumed',
// data: [5, 7, 3]}],
// });
series: [{
name: 'Truepower Consumed',
data: [ '{{ p|join:"','" }}']},
{
name: 'Generator Consumed',
data: [ '{{ q|join:"','" }}']}],
});
});
views.py
def plot_graph(request):
month_number=[]
months=KEBReading.objects.filter().values("datetime_reading")
print months
for obj in months:
month_number=obj["datetime_reading"].day
print month_number
q2=KEBReading.objects.filter().values("truepower_consumed")
print q2
q3=GeneratorReading.objects.filter().values("perday_dgunit")
print q3
for item in q2:
power_values=item["truepower_consumed"]
print power_values
print "tee"
for item in q3:
gen_values=item["perday_dgunit"]
print gen_values
context={'m':month_number,'p':power_values,'q':gen_values}
return render_to_response('graph.html',context,
context_instance=RequestContext(request))
グラフをプロットしようとしています。ビューからグラフのjQueryに値を渡す方法を知ることができますか?context = {'m':month_number、'p':power_values、'q':gen_values} pとqはy軸の値であり、mはx軸の値です。
models.py
class KEBReading(models.Model):
datetime_reading=models.DateTimeField()
truepower_reading=models.DecimalField(verbose_name="True Power Reading(KWH)",max_digits=6,decimal_places=2,blank=False,null=False)
apparentpower_reading=models.DecimalField(verbose_name="Apparent Power Reading(KVAH)",max_digits=6,decimal_places=2,blank=False,null=False)
truepower_consumed=models.DecimalField(max_digits=6,decimal_places=2,blank=False,null=False)
voltage_reading=models.IntegerField(blank=False,null=False)
powerfactor=models.DecimalField(max_digits=3,decimal_places=2)
class GeneratorReading(models.Model):
datetime_reading=models.DateTimeField()
running_time=models.IntegerField(blank=False,null=False)
running_time_consumed=models.SmallIntegerField(blank=False,null=False)
dgunit_reading=models.DecimalField(max_digits=6, blank=True,decimal_places=2)
perday_dgunit=models.DecimalField(max_digits=6, decimal_places=2)