/
historial.js
101 lines (90 loc) · 3.65 KB
/
historial.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
(function ($, Highcharts) {
var HighchartsSpanishOptions = {
lang: {
contextButtonTitle: "Menú de opciones",
downloadJPEG: "Descarga imagen JPEG",
downloadPNG: "Descarga imagen PNG",
downloadSVG: "Descarga imagen SVG ",
downloadPDF: "Descarga documento PDF",
downloadCSV: "Descarga CSV",
decimalPoint: ".",
thousandsSep: ",",
loading: "Cargando...",
months: ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"],
shortMonths: ["Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"],
weekdays: ["Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sabado"],
printChart: "Imprimir gráfico",
rangeSelectorFrom: "Desde",
rangeSelectorTo: "Hasta",
rangeSelectorZoom: "Acercar",
resetZoom: "Alejar"
}
};
Highcharts.setOptions(HighchartsSpanishOptions);
function createChart(pattern) {
var sourceData = {},
countyName,
seriesData = [],
resource_id = "6774c4a2-6c04-4d27-9b7d-3400b7f6725e",
ckan_api = "http://datamx.io/api/action/datastore_search_sql?sql=",
sql = "SELECT \"Municipio\",\"" + pattern + "\" FROM \"" + resource_id + "\" ORDER BY \"NumeroEvaluacion\" ASC";
$.getJSON(ckan_api + sql, function (data) {
for (var i = 0, l = data.result.records.length; i < l; i++) {
countyName = data.result.records[i].Municipio;
if (sourceData[countyName] === undefined) {
sourceData[countyName] = [];
}
sourceData[countyName].push(parseInt(data.result.records[i][pattern], 10));
}
for (var county in sourceData) {
if (sourceData.hasOwnProperty(county)) {
seriesData.push({
name: county,
data: sourceData[county]
});
}
}
$("#container").highcharts({
chart: {
zoomType: "x",
type: "spline"
},
title: {
text: "¿Cómo vamos Nuevo León?"
},
subtitle: {
text: document.ontouchstart === undefined ?
"Clic y arrastre en el área para hacer zoom in" : "Toque la pantalla para hacer zoom in"
},
xAxis: {
type: "datetime",
minRange: 60 * 24 * 3600000 // 60 days
},
yAxis: {
title: {
text: "Evaluación"
}
},
legend: {
enabled: true
},
plotOptions: {
spline: {
pointInterval: 60 * 24 * 3600 * 1000, // 60 days
pointStart: Date.UTC(2013, 2, 25)
}
},
series: seriesData
});
});
}
// Listen for the jQuery ready event on the document
$(function () {
createChart("DepuracionPolicialTransparente");
// When somebody change the revision redraw the chart
$("body").on("change", "#revision", function () {
var targetRevision = $(this).val();
createChart(targetRevision);
});
});
}(window.jQuery, window.Highcharts));