Commit cfc31d1ebff668b9fc23091f971bf8c7c733179a

Authored by Renato De Donato
1 parent 40eb0979

alasql cast

datalets/bar-chart-datalet/bar-chart-datalet.html
... ... @@ -79,8 +79,8 @@ Example:
79 79 text: this._component.title
80 80 },
81 81 xAxis: {
82   -// categories: this.properties.categories.value,
83   - categories: ['Cinesi', 'Albanesi', 'Rumeni', 'Pakistani', 'Marocchini', 'Altri stranieri'],
  82 + categories: this.properties.categories.value,
  83 +// categories: ['Cinesi', 'Albanesi', 'Rumeni', 'Pakistani', 'Marocchini', 'Altri stranieri'],
84 84 title: {
85 85 text: this._component.xAxisLabel
86 86 }
... ... @@ -104,6 +104,10 @@ Example:
104 104 enabled: true
105 105 }
106 106 }
  107 +//
  108 +// series: {
  109 +// stacking: 'normal'
  110 +// }
107 111 },
108 112 legend: {
109 113 layout: 'vertical',
... ... @@ -119,23 +123,24 @@ Example:
119 123 credits: {
120 124 enabled: false
121 125 },
122   -// series: this.properties.series.value
123   - series: [{
124   - name: '2010',
125   - data: [107, 31, 635, 203, 2]
126   - }, {
127   - name: '2011',
128   - data: [1353, 156, 947, 408, 6]
129   - }, {
130   - name: '2012',
131   - data: [133, 156, 947, 408, 64]
132   - }, {
133   - name: '2013',
134   - data: [133, 156, 947, 48, 6]
135   - }, {
136   - name: '2014',
137   - data: [1052, 954, 4250, 740, 38]
138   - }]
  126 +
  127 + series: this.properties.series.value
  128 +// series: [{
  129 +// name: '2010',
  130 +// data: [107, 31, 635, 203, 2]
  131 +// }, {
  132 +// name: '2011',
  133 +// data: [1353, 156, 947, 408, 6]
  134 +// }, {
  135 +// name: '2012',
  136 +// data: [133, 156, 947, 408, 64]
  137 +// }, {
  138 +// name: '2013',
  139 +// data: [133, 156, 947, 48, 6]
  140 +// }, {
  141 +// name: '2014',
  142 +// data: [1052, 954, 4250, 740, 38]
  143 +// }]
139 144 });
140 145  
141 146  
... ...
datalets/base-ajax-json-alasql-datalet/static/js/AjaxJsonAlasqlBehavior.js
... ... @@ -137,15 +137,34 @@ var AjaxJsonAlasqlBehavior = {
137 137 orderBy = orderBy.slice(0, -2);
138 138 }
139 139  
140   - //SELECT;
  140 + //SELECT
141 141 var select = "SELECT ";
142 142 for (var i = 0; i < fields.length; i++)
143   - //select += fields[i] + ", ";
144 143 select += fields[i] + " as " + this._fieldName(this._component.fields[i], "") + ", ";
145 144 select = select.slice(0, -2);
146 145  
147 146 var pureSelect = select;
148 147  
  148 + /**/
  149 + var res = alasql("SELECT "+ path +" FROM ?", [jsonData]);
  150 + var records = res[0][path];
  151 + var obj = alasql(pureSelect + " FROM ?", [records]);
  152 + //console.log(obj);
  153 +
  154 + var select = "SELECT ";
  155 + for (var i = 0; i < fields.length; i++) {
  156 + var key = Object.keys(obj[0])[i];
  157 + var v = obj[0][key];
  158 + if (!isNaN(v))
  159 + select += fields[i] + "::NUMBER as " + this._fieldName(this._component.fields[i], "") + ", ";
  160 + else
  161 + select += fields[i] + " as " + this._fieldName(this._component.fields[i], "") + ", ";
  162 + }
  163 + select = select.slice(0, -2);
  164 +
  165 + var pureSelect = select;
  166 + /**/
  167 +
149 168 //GROUP BY
150 169 var groupBy = "";
151 170 if(aggregators && aggregators.length) {
... ...