Last active
January 3, 2019 15:19
-
-
Save palistha01/f7abdd250051de334c54d1faeba65d1c to your computer and use it in GitHub Desktop.
Displaying dynamic data in barcharts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(52) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}] | |
0: {ward_no: "9"} | |
1: {ward_no: "11"} | |
2: {ward_no: "5"} | |
3: {ward_no: "12"} | |
4: {ward_no: "1"} | |
5: {ward_no: "10"} | |
6: {ward_no: "11"} | |
7: {ward_no: "12"} | |
8: {ward_no: "14"} | |
9: {ward_no: "11"} | |
10: {ward_no: "1"} | |
11: {ward_no: "11"} | |
12: {ward_no: "13"} | |
13: {ward_no: "11"} | |
14: {ward_no: "2"} | |
15: {ward_no: "9"} | |
16: {ward_no: "5"} | |
17: {ward_no: "5"} | |
18: {ward_no: "6"} | |
19: {ward_no: "7"} | |
20: {ward_no: "1"} | |
21: {ward_no: "2"} | |
22: {ward_no: "1"} | |
23: {ward_no: "12"} | |
24: {ward_no: "3"} | |
25: {ward_no: "3"} | |
26: {ward_no: "4"} | |
27: {ward_no: "1"} | |
28: {ward_no: "2"} | |
29: {ward_no: "3"} | |
30: {ward_no: "8"} | |
31: {ward_no: "2"} | |
32: {ward_no: "5"} | |
33: {ward_no: "2"} | |
34: {ward_no: "3"} | |
35: {ward_no: "2"} | |
36: {ward_no: "12"} | |
37: {ward_no: "11"} | |
38: {ward_no: "11"} | |
39: {ward_no: "11"} | |
40: {ward_no: "11"} | |
41: {ward_no: "4"} | |
42: {ward_no: "11"} | |
43: {ward_no: "11"} | |
44: {ward_no: "11"} | |
45: {ward_no: "11"} | |
46: {ward_no: "11"} | |
47: {ward_no: "11"} | |
48: {ward_no: "11"} | |
49: {ward_no: "11"} | |
50: {ward_no: "11"} | |
51: {ward_no: "11"} | |
length: 52 | |
__proto__: Array(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NewRegistration(models.Model): | |
fiscalyear = models.ForeignKey(system_settings.models.FiscalYear) | |
registration_date = models.DateField(max_length=20) | |
date_and_time = models.DateTimeField(auto_now_add=True) | |
houseowner_name_en = models.CharField(max_length=30) | |
houseowner_name_np = models.CharField(max_length=50) | |
ward_no = models.ForeignKey(system_settings.models.Wardno) | |
contactno = models.CharField(max_length=30) | |
construction_type = models.ForeignKey(system_settings.models.ConstructionType) | |
latitude = models.DecimalField(decimal_places=16, max_digits=30) | |
longitude = models.DecimalField(decimal_places=16, max_digits=30) | |
taxpayer_id = models.CharField(max_length=30, blank=True, null=True) | |
cen = models.IntegerField() | |
is_forwarded = models.BooleanField(default=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="chartContainer" style="height: 300px; width: 100%;"></div> | |
<script> | |
function load_monthwise_ward(year, title) { | |
var temp_title = title + ' ' + year + ''; | |
console.log(temp_title); | |
$.ajax({ | |
url: '{% url "ward" %}', | |
type: "GET", | |
data: { | |
"_token": "{% csrf_token %}" | |
}, | |
dataType: "json", | |
success: function (data) { | |
if (data) { | |
var results = data; | |
var data = results.wards; | |
console.log(data); {#console.log(c);#} | |
drawMonthwiseChartWard(data, temp_title); | |
} | |
} | |
}); | |
} | |
function drawMonthwiseChartWard(chart_data, chart_main_title) { | |
var date = $("select#ward").val(); | |
var jsonData = chart_data; | |
var data = new google.visualization.DataTable(); | |
data.addColumn('string', 'Ward'); | |
data.addColumn('number', 'Total'); | |
$.each(jsonData, function (i, jsonData) { | |
var month = date; | |
var profit = jsonData; | |
data.addRows([[month, profit]]); | |
var options = { | |
title: chart_main_title, | |
hAxis: { | |
title: "Ward" | |
}, | |
vAxis: { | |
title: 'Total' | |
} | |
}; | |
var chart = new google.visualization.ColumnChart(document.getElementById('chart_area1')); | |
chart.draw(data, options); | |
}); | |
} | |
$(document).ready(function () { | |
var ward = $('#ward').prop('id') | |
if (ward != '') { | |
load_monthwise_ward(ward, 'Ward'); | |
} | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url(r'^report/$', views.report, name='report'), | |
url(r'^ward/$', views.ward, name='ward'), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def report(request, template_name='report.html'): | |
return render_to_response(template_name, { 'range': range(15)}) | |
def ward(request): | |
results = NewRegistrationModel.objects.all().values('ward_no') | |
return JsonResponse({'wards': list(results)}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment